FFTotoro
2024-10-24 18:48:21
English version of this editorial is provided after the sample code.
本题为交互题,你需要猜
注意,你的询问需要一次性全部给出,之后交互库再进行回答。但是,对于每个
如果交互库不会给出错误的回复,那么解决问题是简单的:考虑二进制拆位,对于每一位,询问值域中所有该位为
如果交互库会在最多一个询问上给出错误的回复呢?考虑给
现在的问题即为构造一组这样的 std::set
,之后找之中没出现过的最小非负整数,将其作为编号分配给下一个整数。用上面的方法进行暴力枚举,发现存在一组构造使得
#include<bits/stdc++.h>
using namespace std;
const int N=2024;
int main(){
ios::sync_with_stdio(false);
vector<int> a; set<int> s;
for(int i=0,x=0;i<=N;i++){
a.emplace_back(x),s.emplace(x);
for(int j=0;j<15;j++)
for(int k=0;k<15;k++)
s.emplace(x^(1<<j)^(j==k?0:(1<<k)));
while(s.find(x)!=s.end())x++;
}
cerr<<a.back()<<endl;
for(int i=0;i<=N;i++)
for(int j=i+1;j<=N;j++)
assert(__builtin_popcount(a[i]^a[j])>=3);
int t; cin>>t;
vector<vector<int> > v(15);
cout<<"15\n";
for(int i=0;i<15;i++){
for(int j=0;j<=N;j++)
if(a[j]>>i&1)
v[i].emplace_back(j);
for(int j:v[i])cout<<j<<' ';
cout<<endl;
}
while(t--){
int c=0,r=-1;
for(int i=0;i<15;i++){
int x; cin>>x;
if(x)c|=1<<i;
}
for(int i=0;i<=N;i++)
if(__builtin_popcount(a[i]^c)<=1)r=i;
cout<<r<<endl;
}
return 0;
}
Translated by ChatGPT
This is an interactive problem, where you need to guess
Note that you must provide all the queries at once, after which the interactor will respond. However, for each
If the interactor never gave incorrect feedback, the solution would be straightforward: Consider the binary representation of each number. For each bit position, query a set consisting of all numbers in the range whose value in that bit position is
However, with the interactor potentially giving an incorrect response for up to one query, we need to take a different approach. We assign a unique "code" to each integer in the range
To determine the answer, suppose we obtain a result
The problem now becomes constructing such a set of std::set
. Then, for each subsequent number, assign the smallest non-negative integer that has not yet been used as a code. Using brute force exploration, we find that there exists a set of codes such that