結果

問題 No.850 企業コンテスト2位
ユーザー face4face4
提出日時 2019-07-08 23:03:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 71,984 KB
実行使用メモリ 24,288 KB
平均クエリ数 200.21
最終ジャッジ日時 2023-09-23 17:50:04
合計ジャッジ時間 3,742 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
24,120 KB
testcase_01 AC 26 ms
23,388 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 24 ms
24,288 KB
testcase_05 WA -
testcase_06 AC 26 ms
23,844 KB
testcase_07 AC 29 ms
23,628 KB
testcase_08 AC 31 ms
23,520 KB
testcase_09 AC 31 ms
23,520 KB
testcase_10 AC 36 ms
23,892 KB
testcase_11 AC 36 ms
23,508 KB
testcase_12 AC 36 ms
23,292 KB
testcase_13 AC 35 ms
23,916 KB
testcase_14 AC 35 ms
23,400 KB
testcase_15 AC 36 ms
23,256 KB
testcase_16 AC 34 ms
23,508 KB
testcase_17 AC 35 ms
23,700 KB
testcase_18 AC 34 ms
23,532 KB
testcase_19 AC 35 ms
23,712 KB
testcase_20 AC 36 ms
23,400 KB
testcase_21 AC 36 ms
23,376 KB
testcase_22 AC 36 ms
23,916 KB
testcase_23 AC 35 ms
24,132 KB
testcase_24 AC 36 ms
23,364 KB
testcase_25 AC 35 ms
23,496 KB
testcase_26 AC 36 ms
24,168 KB
testcase_27 AC 25 ms
24,156 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]);
    answer(ask(defeat[top][0], defeat[top][1]));
    return 0;
}
0