-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12851.cpp
More file actions
31 lines (31 loc) · 700 Bytes
/
12851.cpp
File metadata and controls
31 lines (31 loc) · 700 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
#include <bits/stdc++.h>
using namespace std;
bool vis[200001];
int n, k, ans, cnt;
int main() {
cin >> n >> k;
if(n == k) {
cout << 0 << "\n" << 1;
return 0;
}
queue<pair<int,int>> Q;
Q.push({n, 0});
while(!Q.empty()) {
int curx = Q.front().first;
int time = Q.front().second;
Q.pop();
vis[curx] = true;
if(!cnt && curx == k) {
ans = time;
cnt++;
}
else if(curx == k && ans == time) cnt ++;
int nx = curx + 1;
if(nx <= 200000 && !vis[nx]) Q.push({nx, time + 1});
nx = curx - 1;
if(nx >= 0 && nx <= 200000 && !vis[nx]) Q.push({nx, time + 1});
nx = curx * 2;
if(nx <= 200000 && !vis[nx]) Q.push({nx, time + 1});
}
cout << ans << "\n" << cnt;
}