結果
| 問題 | No.2124 Guess the Permutation |
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2024-05-07 14:32:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 2,000 ms |
| コード長 | 1,265 bytes |
| コンパイル時間 | 2,229 ms |
| コンパイル使用メモリ | 203,596 KB |
| 最終ジャッジ日時 | 2025-02-21 11:35:43 |
|
ジャッジサーバーID (参考情報) |
judge5 / 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);
}
eve__fuyuki