https://www.acmicpc.net/problem/5014
문제 내 point
from collections import deque
n, start, goal, up, down = map(int, input().split())
arr = [0]*(n+1)
visited = [False]*(n+1)
def bfs(start):
q = deque([start])
visited[start] = True
while q:
v = q.popleft()
if v == goal:
return arr[goal]
for next in v+up, v-down:
if 0 < next <= n and not visited[next]:
visited[next] = True
arr[next] = arr[v] + 1
q.append(next) # 값 추가
if arr[goal] == 0:
return "use the stairs"
print(bfs(start))
채점 결과
