結果

問題 No.2124 Guess the Permutation
ユーザー tsugutsugutsugutsugu
提出日時 2022-11-18 21:32:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,324 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 171,156 KB
実行使用メモリ 24,600 KB
平均クエリ数 374.60
最終ジャッジ日時 2023-10-20 06:19:29
合計ジャッジ時間 2,937 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
template <class T = int> using V = vector<T>;
template <class T = int> using VV = vector<V<T>>;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " ";} std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n;
    cin >> n;
    V<> ans(n);
    cout << "? " << 2 << " " << n << endl;
    int x;
    cin >> x;
    ans[0] = n * (n + 1) / 2 - x;
    for (int i = 0; i < n - 2; i++) {
        cout << "? " << i + 1 << " " << i + 2 << endl;
        int r;
        cin >> r;
        ans[i + 1] = r - ans[i];
    }
    V<bool> used(n, false);
    for (int i = 0; i < n - 1; i++) {
        used[ans[i] - 1] = true;
    }
    for (int i = 0; i < n; i++) {
        if (!used[i]) ans[n - 1] = i + 1;
    }
    cout << "! ";
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}
0