Submission #1143481

#TimeUsernameProblemLanguageResultExecution timeMemory
1143481MighilonCOVID tests (CEOI24_covid)C++17
88.16 / 100
509 ms432 KiB
#include <bits/stdc++.h>
using namespace std;
 
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
 
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first 
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
 
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;
 
int n, LOG;
double p;
int block;
vector<bool> ans;

bool ask(int l, int r){
    cout<<"Q ";
    string s(n,'0');
    FOR(i,l,r+1)
        s[i]='1';
    cout<<s;
    cout<<endl;
    char ans;
    cin>>ans;
    return ans=='P';
}
bool ask2(int l,int sz){
    return ask(l,l+sz-1);
}

int f(int L, int R){
    int l=L, r=R;
    int res=R;
    while(l<=r){
        int m=(l+r)/2;
        bool b=ask(L,m);
        if(b){
            res=m;
            r=m-1;
        }
        else{
            l=m+1;
        }
    }
    return res;
}

void solve(){
    int i=0;
    while(i<n){
        bool b=ask(i,min(n-1,i+block-1));
        if(!b)
            i+=block;
        else{
            if(block==3){
                b=ask(i,i);
                if(b){
                    ans[i]=1; i++;
                } 
                else if(i+1==n-1){
                    ans[i+1]=1; i+=2;
                }
                else{
                    if(ask(i+1,i+1)){
                        ans[i+1]=1;
                        if(ask(i+2,i+2))
                            ans[i+2]=1;
                    }
                    else ans[i+2]=1;
                    i+=3;
                }
            }
            else{
                int j=f(i,min(n-1,i+block-1));
                ans[j]=1;
                i=j+1;
            }
        }
    }
    cout<<"A ";
    F0R(i,n)
        cout<<ans[i];
    cout<<endl;
    char c;
    cin>>c;
}
 
int32_t main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int TC = 1;
    // cin >> TC;
    cin>>n>>p>>TC;
    block=1;
    double tmp=1.0-p;
    while(tmp*(1.0-p)>=0.5&&p!=0){
        block++;
        tmp*=(1.0-p);
    }
    dbg(block)
    ans.resize(n);
    while(TC--){
        ans.assign(n,0);
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...