Skip to content

Commit 0672613

Browse files
committed
[BOJ] #1697. 숨바꼭질 / 실버1 / 20분 / 성공
1 parent 014f365 commit 0672613

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
from collections import deque
3+
input = sys.stdin.readline
4+
5+
MAX = 100000
6+
N, K = map(int, input().split())
7+
8+
visited = [0] * (MAX+1)
9+
queue = deque([N])
10+
11+
while queue:
12+
current = queue.popleft()
13+
if current == K:
14+
break
15+
for nx in (current + 1, current - 1, current * 2):
16+
if 0 <= nx <= MAX and not visited[nx]:
17+
visited[nx] = visited[current] + 1
18+
queue.append(nx)
19+
20+
print(visited[K])

0 commit comments

Comments
 (0)