백준 2164번, 카드2
https://www.acmicpc.net/problem/2164
기존 자주 쓰던 list 의 pop 과 append 로는 메모리초과와 시간초과가 발생
deque 를 사용하면 훨씬 빠르게 문제를 해결할 수 있다.
import sys
import collections
input = sys.stdin.readline
n = int(input())
s = [i for i in range(1,n+1)]
s = collections.deque([i for i in range(1,n+1)])
while len(s) > 1:
s.popleft()
s.rotate(-1)
print(s[0])
Reference : https://leonkong.cc/posts/python-deque.html