Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <unordered_map>
- #include <queue>
- using namespace std;
- typedef long long int ll;
- vector<ll> dist;
- const int UNDEF = -1;
- int main() {
- ios_base::sync_with_stdio();
- cin.tie();
- cout.tie();
- ll n;
- int A, B, C;
- cin >> n >> A >> B >> C;
- dist.assign(n + 1, UNDEF);
- queue<ll> q;
- q.push(n);
- dist[n] = 0;
- while(!q.empty()) {
- ll cur = q.front();
- ll next[4];
- if (cur % A == 0)
- next[0] = cur / A;
- else {
- next[0] = cur;
- }
- if(cur % B == 0)
- next[1] = cur / B;
- else next[1] = cur;
- next[2] = cur - 1;
- next[3] = cur - C;
- for(ll nxt : next) {
- if(dist[nxt] == UNDEF) {
- dist[nxt] = dist[cur] + 1;
- q.push(nxt);
- }
- }
- }
- cout << dist[1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement