Submission #920463

# Submission time Handle Problem Language Result Execution time Memory
920463 2024-02-02T15:06:04 Z Pacybwoah Colors (BOI20_colors) C++17
0 / 100
0 ms 344 KB
#include<iostream>
#include<vector>
#define ll long long
using namespace std;
bool ask(ll num){
    cout<<"? "<<num;
    bool ans;
    cin>>ans;
    cout<<endl;
    return ans;
}
int main(){
    ll n;
    cin>>n;
    ll L=0,R=0,last=(1+n)/2-1;
    bool now=1;
    while(last+1<n){
        if(now) L+=(last+1+n)/2-last;
        else R+=(last+1+n)/2-last;
        now=!now;
        last=(last+1+n)/2;
    }
    now=1;
    L++;
    R=n-R;
    ll l=1,r=n;
    bool ans=ask(L);
    ans=ask(R);
    last=(l+r)/2-1;
    if(ans) r=(l+r)/2-1;
    else l=(l+r)/2;
    while(l<r){
        int mid=(l+r)>>1;
        if(mid>last){
            if(now){
                L-=mid-last;
                ans=ask(L);
            }
            else{
                R+=mid-last;
                ans=ask(R);
            }
        }
        else{
            if(now){
                L+=last-mid;
                ans=ask(L);
            }
            else{
                R-=last-mid;
                ans=ask(R);
            }
        }
        now=!now;
        last=mid;
        if(ans) r=mid;
        else l=mid+1;
    }
    cout<<"= "<<l<<"\n";
}
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -