horvathm

Untitled

Dec 14th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_map>
  4.  
  5. int main() {
  6.     std::vector<int> input = { 0, 20, 7, 16, 1, 18, 15 };
  7.     std::unordered_map<int, int> nums;
  8.     int turn = 1;
  9.  
  10.     for (auto&& i : input) {
  11.         nums[i] = turn;
  12.         turn++;
  13.     }
  14.  
  15.     int last = input.back();
  16.  
  17.     while (turn <= 30000000) {
  18.         auto lastturn = nums.find(last);
  19.         nums[last] = turn - 1;
  20.  
  21.         if (lastturn == nums.end()) {
  22.             last = 0;
  23.         } else {
  24.             last = turn - lastturn->second - 1;
  25.         }
  26.  
  27.         turn++;
  28.     }
  29.     std::cout << turn << ' ' << last << std::endl;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment