1 solutions
-
0
#include<bits/stdc++.h> using namespace std; #define int long long int x, y; map<int, int>p; int bfs(int y) { if (x > y)return x - y; if (p[y] > 0) return p[y]; if (x == y)return 0; p[y] = y - x; if (y % 2 == 0) p[y] = min(p[y], bfs(y / 2) + 1); else { p[y] = min(p[y], bfs((y + 1) / 2) + 2); p[y] = min(p[y], bfs((y - 1) / 2) + 2); } return p[y]; } signed main() { cin >> x >> y; cout << bfs(y); }
- 1
Information
- ID
- 582
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- # Submissions
- 71
- Accepted
- 12
- Uploaded By