From 42a59c128c440cdb87c0d7442dc08fd39e324738 Mon Sep 17 00:00:00 2001 From: gmlrude Date: Sat, 15 Feb 2025 17:11:15 +0900 Subject: [PATCH] =?UTF-8?q?80=EC=B0=A8=201=EB=B2=88=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=20=EB=8B=A4=EC=8B=9C=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\225\355\235\254\352\262\275.py" | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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))