From 9ebe6a7fea6093ccb02ca95f7928746f8b4946a3 Mon Sep 17 00:00:00 2001 From: SRASONY Date: Wed, 7 May 2025 00:17:55 +0900 Subject: [PATCH] =?UTF-8?q?[Baekjoon-13549]=20=EC=88=A8=EB=B0=94=EA=BC=AD?= =?UTF-8?q?=EC=A7=88=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\260\224\352\274\255\354\247\210 3.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "BOJ/seulah/14_week/\354\210\250\353\260\224\352\274\255\354\247\210 3.py" diff --git "a/BOJ/seulah/14_week/\354\210\250\353\260\224\352\274\255\354\247\210 3.py" "b/BOJ/seulah/14_week/\354\210\250\353\260\224\352\274\255\354\247\210 3.py" new file mode 100644 index 0000000..94203cd --- /dev/null +++ "b/BOJ/seulah/14_week/\354\210\250\353\260\224\352\274\255\354\247\210 3.py" @@ -0,0 +1,24 @@ +from collections import deque + +N,K = map(int,input().split()) +time = [-1]*100001 + +def bfs(n,k): + if n == k: + return 0 + queue = deque([(n)]) + time[n] = 0 + while queue: + X = queue.popleft() + for nx in [X-1,X+1,2*X]: + if 0<=nx<=100000 and time[nx] ==-1: + if nx == 2*X: + time[nx] = time[X] + queue.appendleft(nx) + else: + time[nx] = time[X]+1 + queue.append(nx) + return time[k] + +print(bfs(N,K)) +