Submission #1092133

#TimeUsernameProblemLanguageResultExecution timeMemory
1092133juicyXoractive (IZhO19_xoractive)C++17
100 / 100
4 ms596 KiB
#include "interactive.h"

#include <bits/stdc++.h>

using namespace std;

void sub(vector<int> &a, vector<int> b) {
  for (int x : b) {
    a.erase(find(a.begin(), a.end(), x));
  }
}

vector<int> qry(vector<int> cnd) {
  vector<int> a = cnd;
  a.push_back(1);
  a = get_pairwise_xor(a);
  sub(a, get_pairwise_xor(cnd));
  a.erase(find(a.begin(), a.end(), 0));
  vector<int> nw;
  for (int i = 0; i < a.size(); i += 2) {
    nw.push_back(a[i]);
  }
  a.swap(nw);
  return a;
}

vector<int> cmb(vector<int> a, vector<int> b) {
  vector<int> res;
  for (int x : a) {
    auto it = find(b.begin(), b.end(), x);
    if (it != b.end()) {
      res.push_back(x);
      b.erase(it);
    }
  }
  return res;
}

vector<int> guess(int n) {
  vector<int> a(n);
  a[0] = ask(1);
  int lg = __lg(n);
  vector<vector<int>> s(lg + 1);
  for (int j = 0; j <= lg; ++j) {
    vector<int> cnd;
    for (int i = 2; i <= n; ++i) {
      if (i >> j & 1) {
        cnd.push_back(i);
      }
    } 
    s[j] = qry(cnd);
  }
  for (int i = n; i > 1; --i) {
    vector<int> b;
    for (int j = 0; j <= lg; ++j) {
      if (i >> j & 1) {
        if (!b.size()) {
          b = s[j];
        } else {
          b = cmb(b, s[j]);
        }
      }
    }
    for (int j = 0; j <= lg; ++j) {
      if (i >> j & 1) {
        s[j].erase(find(s[j].begin(), s[j].end(), b[0]));
      }
    }
    a[i - 1] = b[0] ^ a[0];
  } 
	return a;
}

Compilation message (stderr)

Xoractive.cpp: In function 'std::vector<int> qry(std::vector<int>)':
Xoractive.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for (int i = 0; i < a.size(); i += 2) {
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...