結果

問題 No.850 企業コンテスト2位
ユーザー mtsdmtsd
提出日時 2019-07-05 21:40:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,750 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 83,432 KB
実行使用メモリ 24,360 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:23:45
合計ジャッジ時間 3,766 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,336 KB
testcase_01 AC 27 ms
23,952 KB
testcase_02 AC 27 ms
23,580 KB
testcase_03 AC 26 ms
24,336 KB
testcase_04 AC 26 ms
23,388 KB
testcase_05 AC 26 ms
24,000 KB
testcase_06 AC 26 ms
24,336 KB
testcase_07 AC 31 ms
23,508 KB
testcase_08 AC 32 ms
23,784 KB
testcase_09 AC 33 ms
23,964 KB
testcase_10 AC 37 ms
23,364 KB
testcase_11 AC 37 ms
24,336 KB
testcase_12 AC 37 ms
23,508 KB
testcase_13 AC 36 ms
23,952 KB
testcase_14 AC 36 ms
24,324 KB
testcase_15 AC 35 ms
24,060 KB
testcase_16 AC 36 ms
24,360 KB
testcase_17 AC 36 ms
23,568 KB
testcase_18 AC 36 ms
23,604 KB
testcase_19 AC 36 ms
23,604 KB
testcase_20 AC 36 ms
23,952 KB
testcase_21 AC 36 ms
23,376 KB
testcase_22 AC 36 ms
23,388 KB
testcase_23 AC 36 ms
23,460 KB
testcase_24 AC 37 ms
23,712 KB
testcase_25 AC 37 ms
23,508 KB
testcase_26 AC 37 ms
23,964 KB
testcase_27 AC 26 ms
23,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int q(int a,int b){
    cout << "? " << a << " " << b << endl;
    int res;
    cin >> res;
    return res;
}

int main(){
    int n;
    cin >> n;
    int ans;
    vector<int>a;
    rep(i,n){
        a.push_back(i+1);
    }
    vector<vector<int> > s(n+1);
    int mx = 0;
    while(1){
        vector<int> b;
        int m = a.size();
        if(m==1){
            mx = a[0];
            break;
        }
        rep(i,m/2){
            int p = q(a[2*i],a[2*i+1]);
            b.push_back(p);
            if(p==a[2*i]){
                s[p].push_back(a[2*i+1]);
            }else{
                s[p].push_back(a[2*i]);
            }
        }
        if(m%2){
            b.push_back(a[m-1]);
        }
        a = b;
    }
    a = s[mx];
    while(1){
        vector<int> b;
        int m = a.size();
        if(m==1){
            mx = a[0];
            break;
        }
        rep(i,m/2){
            int p = q(a[2*i],a[2*i+1]);
            b.push_back(p);
            if(p==a[2*i]){
                s[p].push_back(a[2*i+1]);
            }else{
                s[p].push_back(a[2*i]);
            }
        }
        if(m%2){
            b.push_back(a[m-1]);
        }
        a = b;
    }
    cout << "! " << mx << endl;
    return 0;
}
0