Use Deque when pop and append
白駿2164号、カード2
https://www.acmicpc.net/problem/2164
従来の一般的なリストのpopとappendでは、メモリオーバーフローとタイムアウトが発生します.
Dequeを使用すると、問題をより迅速に解決できます.
https://www.acmicpc.net/problem/2164
従来の一般的なリストの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.htmlReference
この問題について(Use Deque when pop and append), 我々は、より多くの情報をここで見つけました https://velog.io/@jolim97/Use-Deque-when-pop-and-appendテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol