結果
問題 | No.2124 Guess the Permutation |
ユーザー |
![]() |
提出日時 | 2024-05-07 14:32:53 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 1,265 bytes |
コンパイル時間 | 2,262 ms |
コンパイル使用メモリ | 209,828 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 374.60 |
最終ジャッジ日時 | 2024-11-30 08:01:55 |
合計ジャッジ時間 | 3,597 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } bool debug = false; int n; vector<int> p, cum; int cnt = 0; int query(int l, int r) { cout << "? " << l << " " << r << endl; cnt++; if (debug) { return cum[r] - cum[l - 1]; } else { int res; cin >> res; return res; } } void answer(vector<int> &a) { cout << "! "; for (int i = 0; i < a.size(); i++) { cout << a[i] << " "; } cout << endl; if (debug) { assert(a == p); assert(cnt < n); } } int main() { fast_io(); cin >> n; if (debug) { p.resize(n); iota(p.begin(), p.end(), 1); shuffle(p.begin(), p.end(), mt19937{random_device{}()}); cum.resize(n + 1); for (int i = 1; i <= n; i++) { cum[i] = cum[i - 1] + p[i - 1]; } } vector<int> a(n); vector<bool> vis(n + 1); a[0] = n * (n + 1) / 2 - query(2, n); vis[a[0]] = true; for (int i = 1; i < n - 1; i++) { a[i] = query(i, i + 1) - a[i - 1]; vis[a[i]] = true; } for (int i = 1; i <= n; i++) { if (!vis[i]) { a[n - 1] = i; } } answer(a); }