|
| 1 | +/* |
| 2 | + * 첫 시도 메모리 초과 |
| 3 | + */ |
| 4 | +import java.io.*; |
| 5 | +import java.util.*; |
| 6 | +public class Boj2346{ |
| 7 | + |
| 8 | + public static void main(String...args) throws Exception{ |
| 9 | + var br = new BufferedReader(new InputStreamReader(System.in)); |
| 10 | + |
| 11 | + var ballonCount = Integer.parseInt(br.readLine()); |
| 12 | + var deque = new ArrayDeque<Ballon>(); |
| 13 | + |
| 14 | + var splitStr = br.readLine().split(" "); |
| 15 | + for(int i = 0 ; i < ballonCount; i++){ |
| 16 | + var element = splitStr[i]; |
| 17 | + deque.offerLast(new Ballon(i+1, Integer.parseInt(element))); |
| 18 | + } |
| 19 | + |
| 20 | + while(deque.size() > 1){ |
| 21 | + var ballon = deque.pollFirst(); |
| 22 | + System.out.print(ballon.startPosition + " "); |
| 23 | + //sb.append(ballon.startPosition).append(" "); |
| 24 | + if(ballon.moveCount < 0){ |
| 25 | + while(ballon.moveCount++ < -1){ |
| 26 | + deque.offerFirst(deque.pollLast()); |
| 27 | + } |
| 28 | + continue; |
| 29 | + } |
| 30 | + if(ballon.moveCount > 0){ |
| 31 | + while(ballon.moveCount-- > 1){ |
| 32 | + deque.offerLast(deque.pollFirst()); |
| 33 | + } |
| 34 | + continue; |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + System.out.print(deque.pollFirst().startPosition); |
| 39 | + //sb.append(deque.pollFirst().startPosition); |
| 40 | + //System.out.print(sb); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +class Ballon{ |
| 45 | + int moveCount; |
| 46 | + int startPosition; |
| 47 | + |
| 48 | + public Ballon(int startPosition, int moveCount){ |
| 49 | + this.startPosition = startPosition; |
| 50 | + this.moveCount = moveCount; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public String toString(){ |
| 55 | + return String.format("moveCount:%d startPosition:%d", moveCount, startPosition); |
| 56 | + } |
| 57 | +} |
| 58 | + |
0 commit comments