horvathm

Untitled

Dec 15th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 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, inserted] = nums.emplace(last, 0);
  19.         if (inserted) {
  20.             last = 0;
  21.         } else {
  22.             last = turn - lastturn->second - 1;
  23.         }
  24.         lastturn->second = turn - 1;
  25.  
  26.         turn++;
  27.     }
  28.  
  29.     std::cout << turn << ' ' << last << std::endl;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment