We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5d6eba8 commit 42a59c1Copy full SHA for 42a59c1
1 file changed
live7/test80/문제1/박희경.py
@@ -4,7 +4,22 @@
4
input = sys.stdin.readline
5
6
n, k = map(int, input().split())
7
-arr = [i for i in range(1, k + 1)]
+visited = [0] * (10 ** 5 + 1)
8
9
10
-# def bfs(x):
+def bfs(x):
11
+ q = deque([x])
12
+ while q:
13
+ x = q.popleft()
14
+ if x == k:
15
+ return visited[x]
16
+ for nx in (x * 2, x - 1, x + 1):
17
+ if 0 <= nx <= 10 ** 5 and not visited[nx]:
18
+ if nx == 2 * x:
19
+ visited[nx] = visited[x]
20
+ else:
21
+ visited[nx] = visited[x] + 1
22
+ q.append(nx)
23
+
24
25
+print(bfs(n))
0 commit comments