https://www.acmicpc.net/problem/1697
문제 내 point
from collections import deque
n, k = map(int, input().split()) # n: 수빈이의 위치, k: 동생의 위치
MAX = 10**6+1
arr = [0]*MAX
def bfs(v):
q = deque([v])
while q:
v = q.popleft()
if v == k:
return arr[v]
for next in v-1, v+1, 2*v:
if 0 <= next < MAX and not arr[next]:
arr[next] = arr[v]+1
q.append(next)
print(bfs(n))
초기 상태
첫 번째 반복
계속 반복
채점 결과

유사 문제 : 백준 5014 스타트링크
https://www.acmicpc.net/problem/5014