Submission #1233472

#TimeUsernameProblemLanguageResultExecution timeMemory
1233472hengliaoCOVID tests (CEOI24_covid)C++20
52.73 / 100
1938 ms480 KiB
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define pll pair<ll, ll>
#define vll vector<ll>
#define pb push_back

typedef long long ll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll a, ll b){
	return rng()%(b-a+1)+a;
}

ll n, t;
double p;

bool qry(string s){
	cout<<"Q "<<s<<endl;
	char re;
	cin>>re;
	if(re=='P') return true;
	return false;
}

void ans(string s){
	cout<<"A "<<s<<endl;
	char re;
	cin>>re;
}

string mrg(string a, string b){
	string re;
	for(ll i=0;i<n;i++){
		if(a[i]=='1' || b[i]=='1') re+='1';
		else re+='0';
	}
	return re;
}

bool check(string s){
	for(ll i=0;i<n;i++){
		if(s[i]=='1') return true;
	}
	return false;
}

string f(ll lef, ll rig, bool exist){
	string tep;
	for(ll i=0;i<n;i++){
		if(i>=lef && i<=rig){
			tep+='1';
		}
		else{
			tep+='0';
		}
	}
	bool re;
	if(!exist) re=qry(tep);
	else re=1;
	if(!re){
		string tep;
		for(ll i=0;i<n;i++){
			tep+='0';
		}
		return tep;
	}
	if(lef==rig){
		string tep;
		for(ll i=0;i<n;i++){
			if(i==lef) tep+='1';
			else tep+='0';
		}
		return tep;
	}
	ll mid=(lef+rig)/2;
	if(rand(0, 1)==0){
		string tep1=f(lef, mid, 0);
		bool dumb=0;
		if(!check(tep1)) dumb=1;
		string tep2=f(mid+1, rig, dumb);
		return mrg(tep1, tep2);
	}
	else{
		string tep2=f(mid+1, rig, 0);
		bool dumb=0;
		if(!check(tep2)) dumb=1;
		string tep1=f(lef, mid, dumb);
		return mrg(tep1, tep2);
	}
	
}

void solve(){
	string s;
	for(ll i=0;i<n;i++) s+='1';
	bool dumb=qry(s);
	if(!dumb){
		s="";
		for(ll i=0;i<n;i++) s+='0';
		ans(s);
		return;
	}
	string a=f(0, n-1, 1);
	ans(a);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin>>n>>p>>t;

	while(t--){
		solve();
	}

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