結果

問題 No.850 企業コンテスト2位
ユーザー merom686merom686
提出日時 2019-07-05 23:35:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 74,188 KB
実行使用メモリ 24,204 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:43:31
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,484 KB
testcase_01 AC 26 ms
23,520 KB
testcase_02 AC 23 ms
23,496 KB
testcase_03 AC 23 ms
24,180 KB
testcase_04 AC 23 ms
23,328 KB
testcase_05 AC 22 ms
23,628 KB
testcase_06 AC 23 ms
23,520 KB
testcase_07 AC 27 ms
24,024 KB
testcase_08 AC 28 ms
23,400 KB
testcase_09 AC 29 ms
23,268 KB
testcase_10 AC 32 ms
23,892 KB
testcase_11 AC 31 ms
23,700 KB
testcase_12 AC 31 ms
23,772 KB
testcase_13 AC 31 ms
23,244 KB
testcase_14 AC 33 ms
23,232 KB
testcase_15 AC 31 ms
24,204 KB
testcase_16 AC 31 ms
23,484 KB
testcase_17 AC 33 ms
24,192 KB
testcase_18 AC 34 ms
23,244 KB
testcase_19 AC 32 ms
23,892 KB
testcase_20 AC 31 ms
23,556 KB
testcase_21 AC 32 ms
23,280 KB
testcase_22 AC 33 ms
24,108 KB
testcase_23 AC 32 ms
23,532 KB
testcase_24 AC 32 ms
24,192 KB
testcase_25 AC 32 ms
24,180 KB
testcase_26 AC 32 ms
23,628 KB
testcase_27 AC 23 ms
24,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int f(int i, int j) {
    cout << "? " << i << ' ' << j << endl;
    int a;
    cin >> a;
    return a;
}

int main() {
    int n;
    cin >> n;

    int p[1024] = {};
    for (int i = 0; i < n; i++) {
        p[i + 512] = i + 1;
    }

    for (int i = 512 - 1; i > 0; i--) {
        if (p[i * 2 + 1] == 0) {
            p[i] = p[i * 2];
        } else {
            p[i] = f(p[i * 2], p[i * 2 + 1]);
        }
    }

    vector<int> q;
    int r = 0;
    for (int i = 1; i < 512;) {
        i = i * 2 + (p[i * 2] != p[i]);
        int t = p[i ^ 1];
        if (r == 0) {
            r = t;
        } else if (t != 0) {
            r = f(r, t);
        }
    }

    cout << "! " << r << endl;

    return 0;
}
0