34 lines
668 B
Python
34 lines
668 B
Python
# 카드2
|
|
|
|
import sys
|
|
|
|
from collections import deque
|
|
|
|
input = sys.stdin.readline
|
|
|
|
|
|
def solution():
|
|
n = int(input().rstrip())
|
|
|
|
cards = deque([i for i in range(1, n+1)])
|
|
|
|
drop_count = 0
|
|
while drop_count < n-1:
|
|
cards.popleft()
|
|
drop_count += 1
|
|
cards.append(cards.popleft())
|
|
|
|
print(cards.pop())
|
|
|
|
return
|
|
|
|
|
|
solution()
|
|
|
|
"""
|
|
걸린 시간: 13분
|
|
|
|
시간 복잡도: deque에 넣고 빼는 작업은 O(1)이므로, 전체 시간복잡도는 O(n)이다.
|
|
|
|
해설: deque에 넣고 진행할 경우 앞, 뒤에 대한 추가, 삭제 연산이 O(1)이므로 이 자료구조를 활용해서 상황을 그대로 구현하면 된다.
|
|
""" |