結果

問題 No.850 企業コンテスト2位
ユーザー nebukuro09nebukuro09
提出日時 2019-07-05 22:10:45
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 1,624 ms
コンパイル使用メモリ 101,140 KB
実行使用メモリ 24,444 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-04 01:51:25
合計ジャッジ時間 4,386 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
23,412 KB
testcase_01 AC 22 ms
24,048 KB
testcase_02 AC 22 ms
23,556 KB
testcase_03 AC 22 ms
23,376 KB
testcase_04 AC 22 ms
24,048 KB
testcase_05 AC 22 ms
24,336 KB
testcase_06 AC 23 ms
24,060 KB
testcase_07 AC 26 ms
24,348 KB
testcase_08 AC 28 ms
23,448 KB
testcase_09 AC 28 ms
24,396 KB
testcase_10 AC 33 ms
24,444 KB
testcase_11 AC 33 ms
23,556 KB
testcase_12 AC 33 ms
23,676 KB
testcase_13 AC 32 ms
23,928 KB
testcase_14 AC 32 ms
23,664 KB
testcase_15 AC 32 ms
23,640 KB
testcase_16 AC 32 ms
24,072 KB
testcase_17 AC 34 ms
24,012 KB
testcase_18 AC 32 ms
23,628 KB
testcase_19 AC 33 ms
23,424 KB
testcase_20 AC 33 ms
24,288 KB
testcase_21 AC 36 ms
24,072 KB
testcase_22 AC 33 ms
23,556 KB
testcase_23 AC 33 ms
23,424 KB
testcase_24 AC 33 ms
24,012 KB
testcase_25 AC 33 ms
24,324 KB
testcase_26 AC 34 ms
23,676 KB
testcase_27 AC 22 ms
23,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

int ask(int a, int b) {
    writeln("? ", a + 1, " ", b + 1);
    stdout.flush;
    return readln.chomp.to!int - 1;
}

void main() {
    auto N = readln.chomp.to!int;

    auto losers = new int[][](N);
    int[] q1;
    int[] q2;
    foreach (i; 0..N) q1 ~= i;

    while (q1.length > 1) {
        q2 = [];
        for (int i = 0; i + 1 < q1.length; i += 2) {
            q2 ~= ask(q1[i], q1[i+1]);
            if (q2.back == q1[i]) {
                losers[q1[i]] ~= q1[i+1];
            } else {
                losers[q1[i+1]] ~= q1[i];
            }
        }
        if (q1.length % 2) {
            q2 ~= q1.back;
        }
        swap(q1, q2);
    }

    q1 = losers[q1.front].dup;
    q2 = [];

    while (q1.length > 1) {
        q2 = [];
        for (int i = 0; i + 1 < q1.length; i += 2) {
            q2 ~= ask(q1[i], q1[i+1]);
        }
        if (q1.length % 2) {
            q2 ~= q1.back;
        }
        swap(q1, q2);
    }

    writeln("! ", q1.front + 1);
}
0