結果

問題 No.850 企業コンテスト2位
ユーザー treeonetreeone
提出日時 2019-07-05 23:40:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 206,408 KB
実行使用メモリ 24,276 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:44:12
合計ジャッジ時間 4,591 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,192 KB
testcase_01 AC 24 ms
23,940 KB
testcase_02 AC 23 ms
23,184 KB
testcase_03 AC 24 ms
23,628 KB
testcase_04 AC 24 ms
24,012 KB
testcase_05 AC 24 ms
23,352 KB
testcase_06 AC 24 ms
24,204 KB
testcase_07 AC 28 ms
23,628 KB
testcase_08 AC 29 ms
23,352 KB
testcase_09 AC 30 ms
24,276 KB
testcase_10 AC 35 ms
23,340 KB
testcase_11 AC 35 ms
23,988 KB
testcase_12 AC 35 ms
23,820 KB
testcase_13 AC 34 ms
23,640 KB
testcase_14 AC 34 ms
23,796 KB
testcase_15 AC 33 ms
23,364 KB
testcase_16 AC 35 ms
23,508 KB
testcase_17 AC 35 ms
24,180 KB
testcase_18 AC 33 ms
23,904 KB
testcase_19 AC 33 ms
23,508 KB
testcase_20 AC 33 ms
24,204 KB
testcase_21 AC 33 ms
24,264 KB
testcase_22 AC 32 ms
23,772 KB
testcase_23 AC 33 ms
24,192 KB
testcase_24 AC 33 ms
24,228 KB
testcase_25 AC 34 ms
23,940 KB
testcase_26 AC 32 ms
23,628 KB
testcase_27 AC 21 ms
23,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a;
    rep(i, 0, n) a.push_back(i);
    int win = -1;
    vector<vector<int> > lose(n);
    while(1){
        if(a.size() == 1){
            win = a[0];
            break;
        }
        vector<int> b;
        for(int i = 0; i < a.size() / 2; i++){
            cout << "? " << a[i * 2] + 1 << ' ' << a[i * 2 + 1] + 1 << endl;
            int in;
            cin >> in;
            in--;
            b.push_back(in); 
            if(a[i * 2] == in) lose[a[i * 2]].push_back(a[i * 2 + 1]);
            else lose[a[i * 2 + 1]].push_back(a[i * 2]);
        }
        if(a.size() % 2 == 1){
            b.push_back(a.back());
        }
        a = b;
    }
    a = lose[win];
    int ans = -1;
    while(1){
        if(a.size() == 1){
            ans = a[0];
            break;
        }
        vector<int> b;
        for(int i = 0; i < a.size() / 2; i++){
            cout << "? " << a[i * 2] + 1 << ' ' << a[i * 2 + 1] + 1 << endl;
            int in;
            cin >> in;
            in--;
            b.push_back(in); 
        }
        if(a.size() % 2 == 1){
            b.push_back(a.back());
        }
        a = b;
    }
    cout << "! " << ans + 1 << endl;
}
0