結果

問題 No.850 企業コンテスト2位
ユーザー chocoruskchocorusk
提出日時 2019-03-27 21:40:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,554 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 83,036 KB
実行使用メモリ 24,420 KB
平均クエリ数 204.07
最終ジャッジ日時 2023-09-23 16:56:51
合計ジャッジ時間 5,339 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,420 KB
testcase_01 AC 27 ms
23,820 KB
testcase_02 AC 26 ms
24,372 KB
testcase_03 AC 26 ms
24,288 KB
testcase_04 AC 26 ms
24,000 KB
testcase_05 AC 25 ms
24,012 KB
testcase_06 AC 25 ms
23,892 KB
testcase_07 AC 30 ms
24,060 KB
testcase_08 AC 31 ms
23,628 KB
testcase_09 AC 31 ms
24,000 KB
testcase_10 AC 36 ms
23,484 KB
testcase_11 AC 36 ms
23,520 KB
testcase_12 AC 37 ms
23,676 KB
testcase_13 AC 35 ms
23,472 KB
testcase_14 WA -
testcase_15 AC 36 ms
24,288 KB
testcase_16 AC 36 ms
24,012 KB
testcase_17 AC 36 ms
24,300 KB
testcase_18 AC 35 ms
23,400 KB
testcase_19 AC 37 ms
23,532 KB
testcase_20 AC 36 ms
23,700 KB
testcase_21 AC 36 ms
24,000 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 25 ms
23,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<random>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
void ask(int x, int y){
    cout<<"? "<<x<<" "<<y<<endl;
}
int main(){
    int n; cin>>n;
    int ret;
    if(n<=168){
        int mx=1, mx2=2;
        ask(1, 2);
        cin>>ret;
        if(ret==2) swap(mx, mx2);
        for(int i=3; i<=n; i++){
            ask(i, mx2);
            cin>>ret;
            if(ret==mx2) continue;
            ask(i, mx);
            cin>>ret;
            if(ret==mx){
                mx2=i;
            }else{
                mx2=mx;
                mx=i;
            }
        }
        cout<<"! "<<mx2<<endl;
        return 0;
    }
    int d=(int)sqrt((double)(2*n));
    int t=0;
    int v=-1;
    set<int> st;
    while(t<d){
        int r=rand()%n+1;
        if(st.find(r)!=st.end()) continue;
        st.insert(r);
        if(v==-1) v=r;
        else{
            ask(v, r);
            cin>>ret;
            v=ret;
        }
        t++;
    }
    vector<int> vec;
    for(int i=1; i<=n; i++){
        if(st.find(i)!=st.end()) continue;
        ask(v, i);
        cin>>ret;
        if(ret==i) vec.push_back(i);
    }
    int mx=v, mx2=vec[0];
    ask(mx, mx2); cin>>ret;
    if(ret==mx2) swap(mx, mx2);
    for(int i=1; i<vec.size(); i++){
        ask(mx2, vec[i]);
        cin>>ret;
        if(ret==mx2) continue;
        ask(mx, vec[i]);
        cin>>ret;
        if(ret==mx) mx2=vec[i];
        else{
            mx2=mx;
            mx=vec[i];
        }
    }
    cout<<"! "<<mx2<<endl;
    return 0;
}
0