Jae-Kyung Cho LLM Developers who was a Robotics engineer

Baekjoon-12851-숨바꼭질 2

N,K = map(int, input().split())

queue = [N]
visited = [[-1,0] for _ in range(int(1e5+1))] # 걸린 시간, 경우의 수
visited[N][0] = 0
visited[N][1] = 1

while queue:
    pos = queue.pop(0)

    for i in [pos+1, pos-1, 2*pos]:
        if 0 <= i <= int(1e5):
            if visited[i][0] == -1:
                visited[i][0] = visited[pos][0] + 1
                visited[i][1] = visited[pos][1]
                queue.append(i)
            else:
                if visited[i][0] == visited[pos][0]+1:
                    visited[i][1] += visited[pos][1]

print(visited[K][0])
print(visited[K][1])
Comments