結果

問題 No.2124 Guess the Permutation
ユーザー RuiRui
提出日時 2022-11-19 20:16:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 3,997 ms
コンパイル使用メモリ 235,040 KB
実行使用メモリ 24,528 KB
平均クエリ数 374.60
最終ジャッジ日時 2023-10-21 01:11:31
合計ジャッジ時間 5,011 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,528 KB
testcase_01 AC 20 ms
24,528 KB
testcase_02 AC 20 ms
24,528 KB
testcase_03 AC 20 ms
24,528 KB
testcase_04 AC 21 ms
24,528 KB
testcase_05 AC 24 ms
24,528 KB
testcase_06 AC 38 ms
24,528 KB
testcase_07 AC 49 ms
24,528 KB
testcase_08 AC 49 ms
24,528 KB
testcase_09 AC 48 ms
24,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
//typedef modint998244353 mint;
typedef modint1000000007 mint;
//const int MOD = 998244353;
const int MOD = 1000000007;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
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; }

int main(){
    int n;
    cin >> n;

    vector<int> ans(n);
    int sum = (n + 1) * n / 2;
    vector<int> r(n, 0);
    rep(i, n - 2){
        int a;
        cout << "? " << i + 2 << ' ' << n << endl;
        cin >> a;
        ans[i] = sum - a - r[i];
        r[i + 1] = r[i] + ans[i];
    }

    int a;
    cout << "? " << 1 << ' ' << n - 1 << endl;
    cin >> a;
    ans[n - 1] = sum - a;

    set<int> s;
    rep(i, n) s.insert(i + 1);
    rep(i, n) s.erase(ans[i]);
    ans[n - 2] = *rbegin(s);

    cout << "! ";
    rep(i, n) cout << ans[i] << ' ';
    cout << endl;

    //4 3 5 1 2

    return 0;
}
0