forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13913.cpp
More file actions
35 lines (33 loc) · 839 Bytes
/
13913.cpp
File metadata and controls
35 lines (33 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Authored by : heheHwang
// Co-authored by : -
// http://boj.kr/fd3427431325431ea6a82e4938589c0d
#include <bits/stdc++.h>
using namespace std;
const int LMT = 100001;
int board[LMT + 2];
int prePos[LMT + 2];
int sis, bro;
queue<int> Q;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> sis >> bro;
board[sis] = 1;
prePos[sis] = sis;
Q.push(sis);
while (!board[bro]) {
int v = Q.front(); Q.pop();
for (int nv : { v + 1, v - 1, 2 * v }) {
if (nv < 0 || LMT <= nv) continue;
if (board[nv]) continue;
board[nv] = board[v] + 1;
prePos[nv] = v;
Q.push(nv);
}
}
cout << board[bro]-1 << '\n';
deque<int> track = {bro};
while (track.front() != sis)
track.push_front(prePos[track.front()]);
for (int p : track) cout << p << ' ';
}