https://www.acmicpc.net/problem/1021
나의 코드
from collections import deque
n, m = map(int, input().split())
position = deque(map(int, input().split()))
queue = deque(i for i in range(1, n+1))
ans = 0
while position:
j = position.popleft()
if j == queue[0]:
queue.popleft()
else:
if queue.index(j) <= len(queue)//2:
k = queue.popleft()
queue.append(k)
ans += 1
else:
k = queue.pop()
queue.appendleft(k)
ans += 1
position.appendleft(j)
print(ans)
결과

문제를 이해 못해서 미량이한테 설명듣고...ㅎㅎ 아무튼 문제에 나와있는대로 구현 성공!ㅎㅎ
'스터디 1일 1커밋' 카테고리의 다른 글
| 240613 [프로그래머스] 42842. 카펫 (1) | 2024.06.13 |
|---|---|
| 240613 [BOJ/백준] 2992. 크면서 작은 수 (0) | 2024.06.13 |
| 240611 [BOJ/백준] 2210. 숫자판 점프 (0) | 2024.06.11 |
| 240610 [BOJ/백준] 1912. 연속합 (0) | 2024.06.10 |
| 240531 [BOJ/백준] 1149. RGB거리 (0) | 2024.05.31 |