https://www.acmicpc.net/problem/14226
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
from collections import deque
def bfs(emo):
global n
queue = deque()
queue.append(emo)
time[emo[0]][emo[1]] = 0
while queue:
s, c = queue.popleft()
for cmd in [(s,s), (s+c,c), (s-1,c)]:
if 0<=cmd[0]<=n and time[cmd[0]][cmd[1]] == -1:
time[cmd[0]][cmd[1]] = time[s][c]+1
queue.append(cmd)
if cmd[0] == n:
return time[cmd[0]][cmd[1]]
n = int(input())
time = [[-1]*(n+1) for _ in range(n+1)]
answer = bfs((1,0))
print(answer)
|
cs |
728x90
반응형
'Problem Solving > BOJ' 카테고리의 다른 글
[Python]1463. 1로 만들기 (0) | 2019.04.02 |
---|---|
[Python]3055. 탈출 (0) | 2019.04.02 |
[Python]2206. 벽 부수고 이동하기 (0) | 2019.04.02 |
[Python]1261. 알고스팟 (0) | 2019.04.02 |
[Python]13549. 숨바꼭질 3 (0) | 2019.04.01 |
댓글