horvathm

Untitled

Dec 23rd, 2020
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include <cstring>
  2. #include <iostream>
  3. #include <map>
  4. #include <list>
  5.  
  6. using namespace std;
  7.  
  8. //const char* input = "389125467"; const int N = 9; const int T = 100;
  9. //const char* input = "974618352"; const int N = 9; const int T = 100;
  10.  
  11. //const char* input = "389125467"; const int N = 1000000; const int T = 10000000;
  12. const char* input = "974618352"; const int N = 1000000; const int T = 10000000;
  13.  
  14. list<int> c;
  15.  
  16. void print_cups(int curr = -1) {
  17.     for (auto&& i : c) {
  18.         if (i != c.front()) {
  19.             cout << ' ';
  20.         }
  21.         if (i == curr) {
  22.             cout << '(' << i + 1 << ')';
  23.         } else {
  24.             cout << i + 1;
  25.         }
  26.     }
  27. }
  28.  
  29. auto next_itr(const list<int>::iterator& itr) {
  30.     auto res = itr;
  31.     res++;
  32.  
  33.     if (res == c.end()) {
  34.         res = c.begin();
  35.     }
  36.     return res;
  37. }
  38.  
  39. int main() {
  40.     int inputLen = strlen(input);
  41.     for (int i = 0; i < inputLen; ++i) {
  42.         c.push_back(input[i] - '0' - 1);
  43.     }
  44.     for (int i = inputLen; i < N; ++i) {
  45.         c.push_back(i);
  46.     }
  47.  
  48.     // for (auto& i : c) {
  49.     //     cout << i + 1 << ", ";
  50.     // }
  51.     // cout << endl;
  52.  
  53.     map<int, list<int>::iterator> ditrs;
  54.     for (auto itr = c.begin(); itr != c.end(); ++itr) {
  55.         ditrs[*itr] = itr;
  56.     }
  57.  
  58.     auto citr = c.begin();
  59.  
  60.     for (int i = 0; i < T; ++i) {
  61.         auto p0 = next_itr(citr);
  62.         auto p1 = next_itr(p0);
  63.         auto p2 = next_itr(p1);
  64.  
  65.         int dest = (*citr + N - 1) % N;
  66.  
  67.         while (dest == *p0 || dest == *p1 || dest == *p2) {
  68.             dest = (dest + N - 1) % N;
  69.         }
  70.  
  71.         auto ditr = ditrs[dest];
  72.         // if (*ditr != dest) {
  73.         //     cout << "whoops" << endl;
  74.         // }
  75.  
  76.         // if (i % 10000 == 0) cout << i << endl;
  77.         // cout << "-- move " << i + 1 << " --" << endl;
  78.         // cout << "cups: ";
  79.         // print_cups(*citr);
  80.         // cout << endl;
  81.         // cout << "pick up: " << *p0 + 1 << ", " << *p1 + 1 << ", " << *p2 + 1 << endl;
  82.         // cout << "destination: " << dest + 1 << endl << endl;
  83.  
  84.         list<int> tmp;
  85.         tmp.splice(tmp.end(), c, p0);
  86.         tmp.splice(tmp.end(), c, p1);
  87.         tmp.splice(tmp.end(), c, p2);
  88.         c.splice(next_itr(ditr), tmp, tmp.begin(), tmp.end());
  89.  
  90.         citr = next_itr(citr);
  91.     }
  92.  
  93.     list<int>::iterator oitr;
  94.     for (auto itr = c.begin(); itr != c.end(); ++itr) {
  95.         if (*itr == 0) {
  96.             oitr = itr;
  97.             break;
  98.         }
  99.     }
  100.  
  101.     // print_cups();
  102.     // cout << endl;
  103.  
  104.     auto out0 = next_itr(oitr);
  105.     auto out1 = next_itr(out0);
  106.  
  107.     cout << *out0 + 1 << ", " << *out1 + 1 << endl;
  108.     cout << int64_t(*out0 + 1) * int64_t(*out1 + 1) << endl;
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment