-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_12851.cpp
More file actions
72 lines (60 loc) · 1.54 KB
/
BOJ_12851.cpp
File metadata and controls
72 lines (60 loc) · 1.54 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 21//11/05
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int subin, sister;
vector<pair<int,int>> arr(100000+1, {-1,0});
queue<int> q;
void Solve(void)
{
arr[subin] = {0,1};
q.push(subin);
while (!q.empty())
{
int now = q.front();
q.pop();
if (now == sister)
break;
if (now > 0)
{
if (arr[now-1].first == arr[now].first+1)
arr[now-1].second += arr[now].second;
if (arr[now-1].first == -1)
{
arr[now-1].first = arr[now].first+1;
arr[now-1].second = arr[now].second;
q.push(now-1);
}
}
if (now < 100000)
{
if (arr[now+1].first == arr[now].first+1)
arr[now+1].second += arr[now].second;
if (arr[now+1].first == -1)
{
arr[now+1].first = arr[now].first+1;
arr[now+1].second = arr[now].second;
q.push(now+1);
}
}
if (now*2 <= 100000)
{
if (arr[now*2].first == arr[now].first+1)
arr[now*2].second += arr[now].second;
if (arr[now*2].first == -1)
{
arr[now*2].first = arr[now].first+1;
arr[now*2].second = arr[now].second;
q.push(now*2);
}
}
}
cout << arr[sister].first << "\n" << arr[sister].second;
}
int main(void)
{
cin >> subin >> sister;
Solve();
return 0;
}