Created
April 16, 2021 18:27
-
-
Save deeev-sb/2ae2c5215a9ef0653b7e168757d50d9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def solution(N, K) : | |
limit = 100001 # 최대로 주어지는 점 + 1 | |
time = [-1] * limit # 시간 저장을 위한 리스트 (방문 여부 확인을 위해 -1로 초기화) | |
time[N] = 0 # 시작은 0초 | |
d = [2, -1, 1] | |
q = deque() | |
q.append(N) | |
while q : | |
X = q.popleft() | |
if X == K : | |
return time[X] | |
for i in range(3) : | |
if i == 0 : # 수빈이가 순간이동하는 경우 | |
nx = X * d[i] | |
if 0 < nx < limit and time[nx] == -1: | |
time[nx] = time[X] | |
q.appendleft(nx) | |
else : # 수빈이가 걷는 경우 | |
nx = X + d[i] | |
if 0 <= nx < limit and time[nx] == -1 : | |
time[nx] = time[X] + 1 | |
q.append(nx) | |
if __name__=="__main__" : | |
N, K = map(int, input().split()) # 수빈이 위치, 동생 위치 | |
print(solution(N, K)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment