1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
from collections import deque
F, S, G, U, D = list(map(int, input().split()))
able=False
dist=[0]*(F+1)
visit=[0]*(F+1)
queue=deque([S])
while queue:
curpos=queue.popleft()
if curpos==G:
able=True
break
visit[curpos]=1
for nextpos in [curpos+U, curpos-D]:
if 1<=nextpos<=F and not visit[nextpos]:
visit[nextpos]=1
dist[nextpos]=dist[curpos]+1
queue.append(nextpos)
print(dist[curpos] if able else 'use the stairs')
|
cs |
'알고리즘 공부' 카테고리의 다른 글
[BOJ] 계단 오르기(2579) 문제 풀이 | Python3 (0) | 2021.05.04 |
---|---|
[Programmers] 타겟 넘버 문제 풀이 | Python3 (0) | 2021.05.03 |
[BOJ] 숨바꼭질(1697) 문제 풀기 | Python3 (0) | 2021.04.30 |
[BOJ] 토마토(7569) 문제 풀기 | Python3 (0) | 2021.04.30 |
[BOJ] 촌수계산(2644) 문제 풀기 | Python3 (0) | 2021.04.29 |