結果

問題 No.2124 Guess the Permutation
ユーザー ruthenruthen
提出日時 2022-11-18 21:35:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 828 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 203,952 KB
実行使用メモリ 24,588 KB
平均クエリ数 374.60
最終ジャッジ日時 2023-10-20 06:21:54
合計ジャッジ時間 3,460 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,588 KB
testcase_01 AC 24 ms
24,588 KB
testcase_02 AC 23 ms
24,588 KB
testcase_03 AC 24 ms
24,588 KB
testcase_04 AC 25 ms
24,588 KB
testcase_05 AC 28 ms
24,588 KB
testcase_06 AC 42 ms
24,588 KB
testcase_07 AC 56 ms
24,588 KB
testcase_08 AC 56 ms
24,588 KB
testcase_09 AC 55 ms
24,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef _RUTHEN
#include <debug.hpp>
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    V<int> P(N);
    int S = N * (N + 1) / 2;
    for (int i = 2; i < N; i++) {
        cout << "? " << i << " " << N << endl;
        int C;
        cin >> C;
        P[i - 2] = S - C;
        S = C;
    }
    cout << "? 1 " << N - 1 << endl;
    int C;
    cin >> C;
    int SS = accumulate(P.begin(), P.begin() + N - 2, 0);
    P[N - 2] = C - SS;
    P[N - 1] = N * (N + 1) / 2 - accumulate(P.begin(), P.begin() + N - 1, 0);
    cout << "! ";
    rep(i, N) cout << P[i] << " \n"[i == N - 1];
    return 0;
}
0