結果

問題 No.2085 Directed Complete Graph
ユーザー だれ
提出日時 2022-09-23 19:02:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 68,104 KB
最終ジャッジ日時 2025-02-07 14:03:53
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

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