#include "interactive.h"
#include <bits/stdc++.h>
using namespace std;
int f;
vector<int> qrs[8], ans;
set<int> res[8], s[405];
set<int> getval(vector<int> v)
{
multiset<int> t, nw;
set<int> ans;
if (v.empty()) return ans;
auto tmp=get_pairwise_xor(v);
for (auto x:tmp) t.insert(x);
v.push_back(1);
tmp=get_pairwise_xor(v);
for (auto x:tmp) nw.insert(x);
for (auto x:t) nw.erase(nw.find(x));
for (auto x:nw) if (x!=0) ans.insert(f^x);
return ans;
}
void solve(int l, int r, int i, int ly, int isl, int rm)
{
if (rm)
{
s[i]=res[ly];
}
else if (isl)
{
for (auto x:s[i/2]) if (res[ly].find(x)!=res[ly].end()) s[i].insert(x);
for (auto x:s[i]) s[i/2].erase(x), res[ly].erase(x);
}
else
{
s[i]=s[i/2];
}
//cout<<"size "<<res[1].size()<<'\n';
//cout<<"debug "<<l<<' '<<r<<' '<<ly<<' '<<isl<<' '<<rm<<' '<<s[i].size()<<'\n';
if (l==r)
{
if (!s[i].empty()) ans.push_back(*s[i].begin());
return;
}
int md=(l+r)/2;
solve(l, md, 2*i, ly+1, 1, r==128);
solve(md+1, r, 2*i+1, ly+1, 0, 0);
}
vector<int> guess(int n) {
f=ask(1);
ans.push_back(f);
for (int i=1; i<=7; i++)
{
for (int j=2; j<=128; j++)
{
if (j>n) continue;
if (((j-1)%(1<<(8-i)))<(1<<(7-i))) qrs[i].push_back(j);
}
res[i]=getval(qrs[i]);
//cout<<"res "<<i<<':';
//for (auto x:res[i]) cout<<x<<' ';
//cout<<'\n';
}
solve(1, 128, 1, 0, 0, 0);
cout<<ans.size()<<'\n';
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Failed |
0 ms |
344 KB |
do not print anything to standard output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Failed |
8 ms |
844 KB |
do not print anything to standard output |
2 |
Halted |
0 ms |
0 KB |
- |