結果

問題 No.2085 Directed Complete Graph
ユーザー だれだれ
提出日時 2022-09-23 19:02:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 69,504 KB
実行使用メモリ 25,196 KB
平均クエリ数 2472.00
最終ジャッジ日時 2024-06-02 00:20:46
合計ジャッジ時間 3,492 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
24,964 KB
testcase_01 AC 20 ms
24,964 KB
testcase_02 AC 147 ms
25,196 KB
testcase_03 AC 135 ms
25,196 KB
testcase_04 AC 156 ms
25,196 KB
testcase_05 AC 78 ms
25,196 KB
testcase_06 AC 81 ms
24,812 KB
testcase_07 AC 138 ms
25,196 KB
testcase_08 AC 108 ms
24,556 KB
testcase_09 AC 138 ms
24,556 KB
testcase_10 AC 140 ms
25,196 KB
testcase_11 AC 139 ms
25,196 KB
testcase_12 AC 141 ms
24,940 KB
testcase_13 AC 144 ms
25,184 KB
testcase_14 AC 143 ms
24,428 KB
testcase_15 AC 20 ms
24,836 KB
testcase_16 AC 20 ms
24,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
using namespace std;

int tmp[2020];
int arr[2020];

void merge_sort(int idx, int _n) {
    if (_n == 1) return;
    auto t = _n / 2;
    merge_sort(idx, t);
    merge_sort(idx + t, _n - t);
    int i = idx, j = idx + t;
    int cnt = 0;
    while (i < idx + t && j < idx + _n) {
        cout << "? " << arr[i] + 1 << " " << arr[j] + 1 << endl;
        int h;
        cin >> h;
        assert(h == 0 || h == 1);
        if (h) {
            tmp[cnt++] = arr[i++];
        }
        else {
            tmp[cnt++] = arr[j++];
        }
    }
    while (i < idx + t) {
        tmp[cnt++] = arr[i++];
    }
    while (j < idx + _n) {
        tmp[cnt++] = arr[j++];
    }
    for (int k = 0; k < _n; k++) {
        arr[idx + k] = tmp[k];
    }
    return;
}

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) arr[i] = i;
    merge_sort(0, n);
    cout << "!" << endl;
    cout << n - 1 << endl;
    for (int i = 0; i < n; i++) cout << arr[i] + 1 << (i == n - 1? "\n": " ");
    return 0;
}
0