practivceAlgorithm/백준
[백준][Python] 18115 카드 놓기
findTheValue
2021. 10. 19. 03:48
deque와 맨앞 요소만 책임지는 front배열을 두어 운용했습니다.
import sys
input = sys.stdin.readline
from collections import deque
N = int(input())
a = list(map(int, input().split()))[::-1]
floor = [i for i in range(N, 1, -1)]
front = [1]
q = deque()
for command in a[1:]:
if command == 1:
q.appendleft(front.pop())
front.append(floor.pop())
elif command == 2:
q.appendleft(floor.pop())
else:
q.append(floor.pop())
answer = front + list(q)
print(*answer)