From 35eecf22946e2f4576db36ad5df248323a987347 Mon Sep 17 00:00:00 2001 From: nkey Date: Mon, 26 Jan 2026 13:49:46 +0900 Subject: [PATCH] =?UTF-8?q?2164-s4=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workbook_8708/2164-s4.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 workbook_8708/2164-s4.py diff --git a/workbook_8708/2164-s4.py b/workbook_8708/2164-s4.py new file mode 100644 index 0000000..4e622a1 --- /dev/null +++ b/workbook_8708/2164-s4.py @@ -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)이므로 이 자료구조를 활용해서 상황을 그대로 구현하면 된다. +""" \ No newline at end of file