Submission #255985

# Submission time Handle Problem Language Result Execution time Memory
255985 2020-08-02T07:31:56 Z 최은수(#5029) Colors (BOI20_colors) C++17
0 / 100
0 ms 384 KB
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
inline int query(ll x)
{
    cout<<"? "<<x;
    int r;
    cin>>r;
    return r;
}
inline void answer(ll x)
{
    cout<<"= "<<x;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    if(n<=64)
    {
        query(1);
        int cp=1;
        int cs=1;
        for(int i=n;i-->1;)
        {
            cp+=cs*i;
            cs*=-1;
            int r=query(cp);
            if(r==0)
            {
                answer(i+1);
                return 0;
            }
        }
        answer(1);
        return 0;
    }
    ll s=1,e=n;
    ll mx=1ll<<(__builtin_clzll(n));
    vector<ll>dv;
    {
        ll dif=1;
        ll cur=n-1;
        while(cur>0)
            dv.eb(cur),cur-=dif,dif*=2;
    }
    ll sign=1;
    ll cur=1;
    for(ll&t:dv)
        cur+=t*sign,sign*=-1;
    query(cur);
    s=1-(mx-n),e=n;
    while(s<e)
    {
        ll m=s+(e-s)/2;
        int res;
        if(m>0)
            cur+=m*sign,sign*=-1,res=query(cur);
        else
            res=0;
        if(res==1)
            e=m;
        else
            s=m+1;
    }
    answer(s);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 384 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 384 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 384 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 384 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 384 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -