답안 #256041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256041 2020-08-02T08:51:03 Z 최은수(#5029) Joker (BOI20_joker) C++17
0 / 100
1 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<<endl;
    int r;
    cin>>r;
    return r;
}
inline void answer(ll x)
{
    cout<<"= "<<x<<endl;
    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;
    }
    if(n<=125)
    {
        query(2);
        int cp=2;
        int cs=1;
        cp+=cs*(n-3);
        cs*=-1;
        if(query(cp)==0)
        {
            if(query(1)==1)
                answer(n-2);
            else if(query(n)==1)
                answer(n-1);
            else
                answer(n);
            return 0;
        }
        for(int i=n-5;i>0;i-=2)
        {
            cp+=cs*i;
            cs*=-1;
            int r=query(cp);
            if(r==0)
            {
                if(query(cp+cs*(i+1))==1)
                    answer(i+1);
                else
                    answer(i+2);
                return 0;
            }
        }
        if(n%2==0)
            answer(1);
        else if(query(cp+cs)==1)
            answer(1);
        else
            answer(2);
        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;
    int cp=0;
    while(s<e)
    {
        ll m=s+(e-s)/2;
        int res;
        if(m>0)
        {
            cur+=m*sign,sign*=-1;
            if(cp!=0)
                query(cur+=sign*cp);
            res=query(cur);
        }
        else
            res=0;
        if(res==1)
            e=m,cp+=(e-s+1)/4;
        else
            s=m+1;
    }
    answer(s);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -