結果

問題 No.2252 Find Zero
ユーザー 0214sh70214sh7
提出日時 2023-03-24 22:02:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,921 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 210,028 KB
実行使用メモリ 24,732 KB
平均クエリ数 49.44
最終ジャッジ日時 2023-10-18 21:04:10
合計ジャッジ時間 4,647 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 59 ms
24,516 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 53 ms
24,516 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 53 ms
24,516 KB
testcase_11 AC 53 ms
24,516 KB
testcase_12 AC 53 ms
24,516 KB
testcase_13 AC 52 ms
24,516 KB
testcase_14 AC 52 ms
24,516 KB
testcase_15 AC 52 ms
24,516 KB
testcase_16 AC 52 ms
24,516 KB
testcase_17 AC 52 ms
24,516 KB
権限があれば一括ダウンロードができます

ソースコード

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();

    if(N==3 || N==5 || N==7){

        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);

    }else{

        ll two = 1;
        vector<ll> D = {0};

        while(2*two-1 < N){
            ll d = D.back();
            D.push_back(phase2_query(d,d));
            two *= 2;
        }

        ll a = -1;
        for(ll i=0;i<N;i++){
            if((N>>i)%2==0)continue;

            if(a==-1){
                a = D[i];
            }else{
                a = phase2_query(D[i],a);
            }
        }

        phase2_answer(a);

    }
    
    return 0;
}
0