Skip to content

Commit

Permalink
80차 1번 문제 다시 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlrude committed Feb 15, 2025
1 parent 5d6eba8 commit 42a59c1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions live7/test80/문제1/박희경.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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))

0 comments on commit 42a59c1

Please sign in to comment.