

from collections import deque
N,M = map(int,input().split())
loca = deque(list(map(int,input().split())))
queue = deque([i for i in range(1,N+1)])
cnt = 0
while loca:
if loca[0] == queue[0]:
queue.popleft()
loca.popleft()
elif queue.index(loca[0]) >= len(queue) / 2:
cnt += 1
queue.appendleft(queue.pop())
else:
cnt += 1
queue.append(queue.popleft())
print(cnt)
3가지 연산 중 3번째 연산을 수행할 때 appendleft를 이용하였다.
queue.index(loca[0]) 값이 len(queue) / 2 와 같거나 크면 3번 연산을 수행하고, 아니면 2번 연산을 수행한다.
| [파이썬/python] 백준 25501번 : 재귀의 귀재 (🥉2) (0) | 2023.06.03 |
|---|---|
| [파이썬/python] 백준 28135번 : Since 1973 (🥉3) (0) | 2023.06.02 |
| [파이썬/python] 백준 1966번 : 프린터 큐 (🥈3) (0) | 2023.05.31 |
| [파이썬/python] 백준 11866번 : 요세푸스 문제 0 (🥈5) (0) | 2023.05.31 |
| [파이썬/python] 백준 2164번 : 카드2(🥈4) (0) | 2023.05.30 |