結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,568 KB
testcase_01 AC 26 ms
23,328 KB
testcase_02 AC 25 ms
23,916 KB
testcase_03 AC 26 ms
23,340 KB
testcase_04 AC 26 ms
23,784 KB
testcase_05 AC 25 ms
23,496 KB
testcase_06 AC 26 ms
23,508 KB
testcase_07 AC 30 ms
23,364 KB
testcase_08 AC 31 ms
23,604 KB
testcase_09 AC 32 ms
23,400 KB
testcase_10 AC 36 ms
23,532 KB
testcase_11 AC 36 ms
23,940 KB
testcase_12 AC 36 ms
23,700 KB
testcase_13 AC 36 ms
24,192 KB
testcase_14 AC 37 ms
23,964 KB
testcase_15 AC 36 ms
24,204 KB
testcase_16 AC 34 ms
23,568 KB
testcase_17 AC 37 ms
23,328 KB
testcase_18 AC 36 ms
23,496 KB
testcase_19 AC 36 ms
23,568 KB
testcase_20 AC 36 ms
23,328 KB
testcase_21 AC 37 ms
23,484 KB
testcase_22 AC 36 ms
23,712 KB
testcase_23 AC 36 ms
23,328 KB
testcase_24 AC 36 ms
23,496 KB
testcase_25 AC 36 ms
23,892 KB
testcase_26 AC 36 ms
23,268 KB
testcase_27 AC 26 ms
23,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    int n, winner;
    cin >> n;
    vector<int> v(2, -1), lose(n+1, -1), cand;

    for(int i=0;i<n;++i) cand.push_back(i+1);
    while(cand.size() > 1) {
        vector<int> next_cand;
        for(int i=0;i<cand.size();i+=2) {
            if(i == cand.size()-1) {
                next_cand.push_back(cand[i]);
                continue;
            }
            cout << "? " << cand[i] << ' ' << cand[i+1] << endl;
            cin >> winner;
            next_cand.push_back(winner);
            if(winner == cand[i]) {
                lose[cand[i+1]] = cand[i];
            } else {
                lose[cand[i]] = cand[i+1];
            }
        }
        swap(cand, next_cand);
    }
    v[0] = cand[0];

    cand.clear();
    for(int i=1;i<=n;++i) {
        if(lose[i] == v[0]) {
            cand.push_back(i);
        }
    }

    while(cand.size() > 1) {
        vector<int> next_cand;
        for(int i=0;i<cand.size();i+=2) {
            if(i == cand.size()-1) {
                next_cand.push_back(cand[i]);
                continue;
            }
            cout << "? " << cand[i] << ' ' << cand[i+1] << endl;
            cin >> winner;
            next_cand.push_back(winner);
        }
        swap(cand, next_cand);
    }

    cout << "! " << cand[0] << endl;
}
0