結果

問題 No.2085 Directed Complete Graph
ユーザー だれだれ
提出日時 2022-09-23 22:55:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 69,916 KB
実行使用メモリ 24,336 KB
平均クエリ数 2472.00
最終ジャッジ日時 2023-08-24 03:08:05
合計ジャッジ時間 3,746 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,336 KB
testcase_01 AC 24 ms
23,388 KB
testcase_02 AC 153 ms
24,048 KB
testcase_03 AC 144 ms
24,036 KB
testcase_04 AC 163 ms
24,324 KB
testcase_05 AC 85 ms
23,520 KB
testcase_06 AC 89 ms
24,312 KB
testcase_07 AC 149 ms
23,412 KB
testcase_08 AC 117 ms
23,364 KB
testcase_09 AC 145 ms
23,664 KB
testcase_10 AC 152 ms
24,060 KB
testcase_11 AC 151 ms
23,904 KB
testcase_12 AC 150 ms
24,024 KB
testcase_13 AC 152 ms
23,820 KB
testcase_14 AC 153 ms
23,712 KB
testcase_15 AC 24 ms
23,364 KB
testcase_16 AC 23 ms
23,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int tmp[505];
int arr[505];

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;
        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 << "!" << "\n";
    cout << n - 1 << "\n";
    for (int i = 0; i < n; i++) cout << arr[i] + 1 << (i == n - 1? "\n": " ");
    return 0;
}
0