문제 : https://www.acmicpc.net/problem/16953

#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
int A, B;
void input(){
cin >> A >> B;
}
void solve(){
queue<pair<long long, long long>> q;
q.push({A, 1}); //실제 값, 인덱스
while(!q.empty()){
pair<long long, long long> cur = q.front();
q.pop();
if(cur.first == B){
cout << cur.second;
return;
}
if(cur.first * 2 <= B){
q.push({cur.first * 2, cur.second + 1});
}
if(cur.first * 10 + 1 <= B){
q.push({cur.first * 10 + 1, cur.second + 1});
}
}
if(q.empty()){
cout << "-1";
return;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
input();
solve();
return 0;
}
