Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <unordered_map>
  6. #include <queue>
  7. using namespace std;
  8.  
  9. typedef long long int ll;
  10.  
  11. vector<ll> dist;
  12. const int UNDEF = -1;
  13. int main() {
  14. ios_base::sync_with_stdio();
  15. cin.tie();
  16. cout.tie();
  17. ll n;
  18. int A, B, C;
  19. cin >> n >> A >> B >> C;
  20. dist.assign(n + 1, UNDEF);
  21. queue<ll> q;
  22. q.push(n);
  23. dist[n] = 0;
  24. while(!q.empty()) {
  25. ll cur = q.front();
  26. ll next[4];
  27. if (cur % A == 0)
  28. next[0] = cur / A;
  29. else {
  30. next[0] = cur;
  31. }
  32. if(cur % B == 0)
  33. next[1] = cur / B;
  34. else next[1] = cur;
  35. next[2] = cur - 1;
  36. next[3] = cur - C;
  37. for(ll nxt : next) {
  38. if(dist[nxt] == UNDEF) {
  39. dist[nxt] = dist[cur] + 1;
  40. q.push(nxt);
  41. }
  42. }
  43. }
  44. cout << dist[1];
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement