2164-s4 성공
This commit is contained in:
34
workbook_8708/2164-s4.py
Normal file
34
workbook_8708/2164-s4.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# 카드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)이므로 이 자료구조를 활용해서 상황을 그대로 구현하면 된다.
|
||||
"""
|
||||
Reference in New Issue
Block a user