-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13549.py
36 lines (31 loc) · 909 Bytes
/
13549.py
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
26
27
28
29
30
31
32
33
34
35
36
# 숨바꼭질 3
import sys
from collections import deque
input = sys.stdin.readline
N, K = map(int, input().split(" "))
Location = [0 for _ in range(K * 2 + 1)]
if K <= N:
print(N - K)
else:
root = deque([[N, 1]])
while root:
pos, time = root.popleft()
while True:
if pos == 0:
Location[pos] = time
if not Location[pos + 1]:
root.append([pos + 1, time + 1])
break
if pos < K * 2:
if not Location[pos]:
Location[pos] = time
if not Location[pos + 1]:
root.append([pos + 1, time + 1])
if not Location[pos - 1]:
root.append([pos - 1, time + 1])
pos *= 2
else:
break
if Location[K]:
break
print(Location[K] - 1)