#include <bits/stdc++.h>
using namespace std;

#define X first
#define Y second

int dx[]={-1,1};
int n,k;
int board[100005];
int pre[100005];


int main() {
    ios::sync_with_stdio(0);
    fill(board,board+100005,-1);
    cin.tie(0);
    cin >> n >> k;
    if(n==k) {
        cout << 0 << '\n' << n;
        return 0;
    }
    queue<int> q;

    pre[n]=n;
    board[n]=0;
    q.push(n);
    while(!q.empty()) {
        int cur=q.front(); q.pop();
        for(int idx=0; idx<3; idx++) {
            int nx;
            if(idx==2) nx=cur*2;
            else nx=cur+dx[idx];

            if(nx<0 || nx>100005) continue;
            if(board[nx]!=-1) continue;

            q.push(nx);
            board[nx]=board[cur]+1;
            pre[nx]=cur;
        }
    }
    cout << board[k]<<'\n';
    //d역추적
    deque<int> dq={k};
    while(dq.front()!=n) {
        dq.push_front(pre[dq.front()]);
    }
    // int now=k;
    //vector<int> path;
    //while(cur!=n) {
    //    path.push.back(cur);
    //    cur=pre[cur];
    //}
    //path.push.back(n);
    //reverse(path.begin(),path.end());
    for(int c:dq) cout << c << ' ';
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: