코딩문제
백준 1697번 숨바꼭질
JihyunLee
2022. 6. 16. 16:42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import sys
from collections import deque
line = sys.stdin.readline().split()
N, K =int(line[0]),int(line[1])
move = deque()
move.append(N)
visit = [0] * (100000+1)
while move:
loc= move.popleft()
if loc == K:
print(visit[loc])
break
else:
for nx in (loc-1, loc+1, loc*2):
if 0<=nx<=100000 and not visit[nx]:
visit[nx]=visit[loc] +1
move.append(nx)
|
cs |