STANAANDREY

AOCMMXX d15p1/2

Dec 16th, 2020 (edited)
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int solve(deque<int> dq, int n) {
  5.     unordered_map<int, int> memory;
  6.     int curr = 0, last = -1;
  7.     for (int i = 1; i <= n; i++) {
  8.         if (dq.size()) {
  9.             curr = dq.front();
  10.             dq.pop_front();
  11.         } else {
  12.             if (!memory.count(last)) {
  13.                 curr = 0;
  14.             } else {
  15.                 curr = i - memory[last];
  16.             }
  17.         }
  18.         memory[last] = i;
  19.         last = curr;
  20.     }
  21.     return curr;
  22. }
  23.  
  24. int main() {
  25.     const deque<int> dq = {
  26.         #include "text.in"
  27.     };
  28.     cout << solve(dq, 2020) << endl;//1
  29.     cout << solve(dq, 3e7) << endl;//2
  30.     return 0;
  31. }
  32.  
Add Comment
Please, Sign In to add comment