Submission #1233489

#TimeUsernameProblemLanguageResultExecution timeMemory
1233489hengliaoCOVID tests (CEOI24_covid)C++20
35.06 / 100
1601 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 B;

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){
	if(lef>rig){
		string tep;
		for(ll i=0;i<n;i++){
			tep+='0';
		}
		return tep;
	}


	double stupid=(double) (rig-lef+1)*p;

	if(stupid<1.4){
		vector<bool> v(n);

		auto ff=[&](ll tar){
			string tep;
			for(ll i=0;i<n;i++){
				if(i>=lef && i<=rig && i<=tar && !v[i]){
					tep+='1';
				}
				else{
					tep+='0';
				}
			}
			return qry(tep);
		};	

		ll pre=lef-1;

		while(pre<rig){
			ll l=pre+1, r=rig;
			ll good=-1;
			while(l<=r){
				ll mid=(l+r)/2;
				if(ff(mid)){
					good=mid;
					r=mid-1;
				}
				else{
					l=mid+1;
				}
			}
			if(good==-1) break;
			v[good]=1;
			pre=good;
		}

		string tep;
		for(ll i=0;i<n;i++){
			if(v[i]) tep+='1';
			else tep+='0';
		}

		// ans(tep);
		return tep;
	}

	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;
	}

	

	if(rig-lef+1==2){
		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);
		}
	}
	else{
		ll diff=(rig-lef)/3;
		ll mid1=lef+diff;
		ll mid2=rig-diff;
		string tep1=f(lef, mid1, 0);
		string tep2=f(mid1+1, mid2-1, 0);
		bool dumb=0;
		if(!check(tep1) && !check(tep2)) dumb=1;
		string tep3=f(mid2, rig, dumb);
		return mrg(mrg(tep1, tep2), tep3);
	}
	
	
}

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...