結果

問題 No.2252 Find Zero
ユーザー 0214sh7
提出日時 2023-03-24 22:09:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,360 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 196,816 KB
最終ジャッジ日時 2025-02-11 17:21:14
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define ALL(v) (v).begin(), (v).end()
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

ll N;
void phase1_input(){
    cin >> N;
}

ll phase2_query(ll x,ll y){
    cout << "? " << x << " " << y << endl;
    ll z;
    cin >> z;
    return z;
}

void phase2_answer(ll k){
    cout << "! " << k << endl;
    exit(0);
}

int main(void){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    
    phase1_input();

    set<ll> R;
    REP(i,N){R.insert(i);}

    REP(i,(N-1)/2){
        auto it = R.begin();
        ll t1 = *it;
        R.erase(it);
        auto it2 = R.begin();
        ll t2 = *it2;
        R.erase(it2);

        ll s = phase2_query(t1,t2);
        if(s==t1){
            phase2_answer(t2);
        }else if(s==t2){
            phase2_answer(t1);
        }

    }

    auto it = R.begin();
    ll t = *it;
    R.erase(it);
    phase2_answer(t);
    
    return 0;
}
0