結果

問題 No.850 企業コンテスト2位
ユーザー face4face4
提出日時 2019-07-08 23:05:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 73,108 KB
実行使用メモリ 24,336 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:50:39
合計ジャッジ時間 3,313 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,880 KB
testcase_01 AC 26 ms
24,180 KB
testcase_02 AC 25 ms
24,168 KB
testcase_03 AC 25 ms
23,976 KB
testcase_04 AC 26 ms
23,520 KB
testcase_05 AC 26 ms
23,400 KB
testcase_06 AC 26 ms
24,336 KB
testcase_07 AC 30 ms
23,760 KB
testcase_08 AC 31 ms
23,880 KB
testcase_09 AC 32 ms
23,892 KB
testcase_10 AC 37 ms
23,412 KB
testcase_11 AC 37 ms
24,144 KB
testcase_12 AC 37 ms
23,808 KB
testcase_13 AC 36 ms
23,640 KB
testcase_14 AC 36 ms
23,904 KB
testcase_15 AC 36 ms
23,556 KB
testcase_16 AC 35 ms
23,256 KB
testcase_17 AC 37 ms
23,916 KB
testcase_18 AC 35 ms
24,192 KB
testcase_19 AC 37 ms
23,544 KB
testcase_20 AC 36 ms
23,388 KB
testcase_21 AC 36 ms
23,400 KB
testcase_22 AC 37 ms
23,640 KB
testcase_23 AC 36 ms
23,520 KB
testcase_24 AC 37 ms
23,640 KB
testcase_25 AC 36 ms
23,520 KB
testcase_26 AC 37 ms
23,532 KB
testcase_27 AC 26 ms
23,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

vector<int> defeat[300];

int ask(int x, int y){
    cout << "? " << x << " " << y << endl << flush;
    int ret;
    cin >> ret;
    if(ret == x)    defeat[x].push_back(y);
    else            defeat[y].push_back(x);
    return ret;
}

void answer(int x){
    cout << "! " << x << endl << flush;
}

void shrink(vector<int> &a){
    while(a.size() > 2){
        vector<int> b;
        int pos = 0;
        while(pos+1 < a.size()){
            b.push_back(ask(a[pos], a[pos+1]));
            pos += 2;
        }
        if(pos < a.size())  b.push_back(a[pos]);
        a = b;
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> a;
    for(int i = 1; i <= n; i++) a.push_back(i);
    shrink(a);
    int top = ask(a[0], a[1]);
    shrink(defeat[top]);
    if(defeat[top].size() == 1){
        answer(defeat[top][0]);
    }else{
        answer(ask(defeat[top][0], defeat[top][1]));
    }
    return 0;
}
0