[백준 5014번] 스타트링크

박형진·2023년 1월 31일
0

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')
profile
안녕하세요!

0개의 댓글