Advertisement
erek1e

IZhO '19 P4 - Xoractive

Feb 20th, 2023
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include "interactive.h"
  2. #include <map>
  3.  
  4. using namespace std;
  5.  
  6. vector<int> guess(int n) {
  7.     int x = ask(1), maxBit = 0;
  8.     while ((1 << (maxBit+1)) <= n-1) ++maxBit;
  9.     auto getVals = [&x](vector<int> v) {
  10.         vector<int> p = get_pairwise_xor(v);
  11.         v.push_back(1);
  12.         vector<int> q = get_pairwise_xor(v);
  13.         vector<int> vals;
  14.         for (int i = 0, j = 0; j < q.size(); ++j) {
  15.             if (i < p.size() && p[i] == q[j]) ++i;
  16.             else if (q[j]) vals.push_back(q[j] ^ x);
  17.         }
  18.         return vals;
  19.     };
  20.  
  21.     map<int, int> where; // value to index
  22.     for (int i = 0; i <= maxBit; ++i) {
  23.         vector<int> v;
  24.         for (int j = 2; j <= n; ++j) {
  25.             if ((j-1) & (1 << i)) v.push_back(j);
  26.         }
  27.         vector<int> res = getVals(v);
  28.         for (int y : res) where[y] |= (1 << i);
  29.     }
  30.  
  31.     vector<int> ans(n); ans[0] = x;
  32.     for (auto [y, i] : where) ans[i] = y;
  33.     return ans;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement