from collections import deque

def bfs():
    q = deque([n])
    while q:
        x = q.popleft()
        if x == k:
            return array[x]
        for nx in (x-1, x+1, 2*x):
            if 0 <= nx < MAX and not array[nx]:
                if nx == 2*x and x != 0:
                    array[nx] = array[x] 
                    q.appendleft(nx) # 2*X 가 더 높은 우선순위를 가지기 위함
                else:
                    array[nx] = array[x] + 1
                    q.append(nx)
    
MAX = 100001
n, k = map(int, input().split())
array = [0] * MAX
print(bfs())

'코딩테스트 > BOJ' 카테고리의 다른 글

[BOJ] 16929 Two Dots (python)  (0) 2020.09.03
[BOJ] 10026 적록색약 (python)  (0) 2020.09.03
백준 #5052 전화번호목록 (Python)  (0) 2020.04.16
백준 #9251 LCS [Python]  (0) 2020.03.27
백준 #1655 가운데를 말해요 [Python]  (0) 2020.03.27
x= input()
y= input()

dp = [[0] * (len(y)+1) for _ in range(len(x)+1)]

for i in range(1, len(x)+1):
    for j in range(1, len(y)+1):
        if x[i-1]==y[j-1]:
            dp[i][j] = dp[i-1][j-1] +1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

print(dp[len(x)][len(y)])
import sys 
import heapq

max_heap = []
min_heap = []

for _ in range(int(input())):
    num = int(sys.stdin.readline())
    if len(max_heap) == len(min_heap):
        heapq.heappush(max_heap, (-num, num))
    else:
        heapq.heappush(min_heap, (num, num))

    if min_heap and max_heap[0][1] > min_heap[0][1]:
        max_value = heapq.heappop(max_heap)[1]
        min_value = heapq.heappop(min_heap)[1]
        heapq.heappush(min_heap, (max_value, max_value))
        heapq.heappush(max_heap, (-min_value, min_value))

    print(max_heap[0][1])

'코딩테스트 > BOJ' 카테고리의 다른 글

[BOJ] 16929 Two Dots (python)  (0) 2020.09.03
[BOJ] 10026 적록색약 (python)  (0) 2020.09.03
백준 #5052 전화번호목록 (Python)  (0) 2020.04.16
백준 #13549 숨바꼭질3 (Python)  (0) 2020.04.12
백준 #9251 LCS [Python]  (0) 2020.03.27

+ Recent posts