★index 활용 ★회전하는 [백준 파이썬 1021번]
2023. 4. 26. 15:49
728x90
반응형
https://www.acmicpc.net/problem/1021
import sys
from collections import deque
N,M = list(map(int , sys.stdin.readline().split()))
res = deque(map(int , sys.stdin.readline().split()))
A = deque(i for i in range(1,N+1))
cnt= 0
# print(A.index(res[0]))
while True:
if len(res) == 0:
break
if A[0] == res[0]:
A.popleft()
res.popleft()
elif len(A) - A.index(res[0]) >= A.index(res[0]):
A.append(A.popleft())
# print(A)
cnt+=1
else:
A.appendleft(A.pop())
# print(A)
cnt+=1
print(cnt)
==> index 활용!!
728x90
반응형
'Python(백준) > 큐,덱' 카테고리의 다른 글
VER2.0★reverse(),덱 string 자르기★AC[백준 파이썬 5430번] (1) | 2023.04.26 |
---|---|
★VER2.0★enumerate, lambda 정렬★프린터 큐[백준 파이썬 1966번] (0) | 2023.04.24 |
★str, join 기억하기★VER2.0★요세푸스문제0[백준 파이썬 11866번]★ (0) | 2023.04.24 |
[백준 파이썬 11286번]★절댓값 힙 구현하기★heap.heappush(리스트 , (우선순위 비교값_1) , (우선순위 비교값_2)★heap.heappop(리스트) ==> 우선순위에 따른 pop() (1) | 2022.12.31 |
★큐,덱★Ver2.0★카드2[백준 파이썬 2164번] (0) | 2022.12.31 |