結果

問題 No.2085 Directed Complete Graph
ユーザー ぷらぷら
提出日時 2022-09-26 01:23:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,501 bytes
コンパイル時間 2,060 ms
コンパイル使用メモリ 203,272 KB
実行使用メモリ 24,384 KB
平均クエリ数 1576.35
最終ジャッジ日時 2023-08-24 03:08:36
合計ジャッジ時間 4,865 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,844 KB
testcase_01 AC 25 ms
23,652 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 56 ms
23,640 KB
testcase_06 AC 59 ms
23,556 KB
testcase_07 AC 95 ms
24,036 KB
testcase_08 AC 74 ms
23,604 KB
testcase_09 AC 94 ms
23,400 KB
testcase_10 AC 100 ms
23,628 KB
testcase_11 AC 96 ms
23,664 KB
testcase_12 AC 93 ms
23,628 KB
testcase_13 AC 95 ms
24,372 KB
testcase_14 AC 98 ms
23,388 KB
testcase_15 AC 24 ms
23,700 KB
testcase_16 AC 23 ms
23,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int>ans;
    ans.push_back(1);
    for(int i = 2; i <= N; i++) {
        cout << "? " << ans.back() << " " << i << endl;
        int f;
        cin >> f;
        if(f) {
            ans.push_back(i);
            continue;
        }
        if(i == 2) {
            ans = {2,1};
            continue;
        }
        cout << "? " << i << " " << ans[0] << endl;
        cin >> f;
        if(f) {
            vector<int>nxt;
            nxt.push_back(i);
            for(int j:ans) nxt.push_back(j);
            ans = nxt;
            continue;
        }
        if(i == 3) {
            ans = {ans[0],i,ans[1]};
            continue;
        }
        int l = 0,r = i-2;
        while(l+1 < r) {
            int mid = (l+r)/2;
            cout << "? " << ans[mid] << " " << i << endl;
            cin >> f;
            if(f) {
                l = mid;
            }
            else {
                r = mid;
            }
        }
        vector<int>nxt;
        for(int j = 0; j < ans.size(); j++) {
            if(j <= l) {
                nxt.push_back(ans[j]);
            }
            if(j == l) {
                nxt.push_back(i);
            }
            if(l < j) {
                nxt.push_back(ans[j]);
            }
        }
        ans = nxt;
    }
    cout << "!" << endl;
    cout << N-1 << endl;
    for(int i = 0; i <= N; i++) {
        cout << ans[i] << ((i == N)?"\n":" ");
    }
}
0