Submission #862678

#TimeUsernameProblemLanguageResultExecution timeMemory
862678Dec0DeddXoractive (IZhO19_xoractive)C++14
100 / 100
5 ms600 KiB
#include <bits/stdc++.h>
#include "interactive.h"

using namespace std;

int msb(int n) {
    if (n == 0) return -1;

    int k=0; n/=2;
    while (n != 0) ++k, n/=2;
    return k;
}

vector<int> guess(int n) {
    vector<int> ans(n);

    ans[0]=ask(1);
    map<int, bool> cnt[15];
    for (int i=0; (1<<i)<=n; ++i) {
        vector<int> x;
        for (int j=2; j<=n; ++j) {
            if (j&(1<<i)) x.push_back(j);
        }

        auto lf=get_pairwise_xor(x);
        x.push_back(1);
        auto rf=get_pairwise_xor(x);

        map<int, int> mp; --mp[0];
        for (auto u : lf) --mp[u];
        for (auto u : rf) ++mp[u];
        for (auto u : mp) {
            if (u.second > 0) cnt[i][u.first^ans[0]]=1;
        }
    }

    for (int i=2; i<=n; ++i) {
        int m=msb(i);

        for (auto u : cnt[m]) {
            if (u.second == 0) continue; 
            bool ok=true;

            for (int j=0; (1<<j)<=n; ++j) {
                if (i&(1<<j)) {
                    if (cnt[j][u.first] == 0) ok=false;
                } else {
                    if (cnt[j][u.first] > 0) ok=false;
                }
            }

            if (ok) {
                ans[i-1]=u.first;
                break;
            }
        }
    }

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...