diff --git "a/live7/test80/\353\254\270\354\240\2341/\353\260\225\355\235\254\352\262\275.py" "b/live7/test80/\353\254\270\354\240\2341/\353\260\225\355\235\254\352\262\275.py" index e2b07079..35535c49 100644 --- "a/live7/test80/\353\254\270\354\240\2341/\353\260\225\355\235\254\352\262\275.py" +++ "b/live7/test80/\353\254\270\354\240\2341/\353\260\225\355\235\254\352\262\275.py" @@ -4,7 +4,22 @@ input = sys.stdin.readline n, k = map(int, input().split()) -arr = [i for i in range(1, k + 1)] +visited = [0] * (10 ** 5 + 1) -# def bfs(x): \ No newline at end of file +def bfs(x): + q = deque([x]) + while q: + x = q.popleft() + if x == k: + return visited[x] + for nx in (x * 2, x - 1, x + 1): + if 0 <= nx <= 10 ** 5 and not visited[nx]: + if nx == 2 * x: + visited[nx] = visited[x] + else: + visited[nx] = visited[x] + 1 + q.append(nx) + + +print(bfs(n))