https://www.acmicpc.net/problem/5014
1. 코드
import sys
from collections import deque
F, S, G, U, D = map(int, sys.stdin.readline().rstrip().split())
result = []
flag = False
visited = [False] * (F+1)
q = deque()
q.append((S, 0))
while q:
curr, cnt = q.popleft()
if curr == G:
flag = True
result.append(cnt)
break
up = curr + U
down = curr - D
if up <= F and not visited[up]:
q.append((up, cnt+1))
visited[up] = True
if down >= 1 and not visited[down]:
q.append((down, cnt+1))
visited[down] = True
if flag:
print(sorted(result)[0])
else:
print('use the stairs')