結果
| 問題 | No.2124 Guess the Permutation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-12 09:35:12 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 2,000 ms |
| コード長 | 851 bytes |
| 記録 | |
| コンパイル時間 | 3,914 ms |
| コンパイル使用メモリ | 334,408 KB |
| 実行使用メモリ | 28,720 KB |
| 平均クエリ数 | 374.60 |
| 最終ジャッジ日時 | 2026-03-12 09:35:26 |
| 合計ジャッジ時間 | 5,738 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void ask(int l, int r) {
cout << "? " << l << " " << r << endl; // endlでflush
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
ll total = 1LL * n * (n + 1) / 2;
vector<ll> pref(n + 1, 0); // pref[i] = sum(1..i)
for (int i = 2; i <= n - 1; i++) {
ask(1, i);
cin >> pref[i];
}
ll sum2n;
ask(2, n);
cin >> sum2n;
vector<ll> ans(n + 1);
ans[1] = total - sum2n;
pref[1] = ans[1];
for (int i = 2; i <= n - 1; i++) {
ans[i] = pref[i] - pref[i - 1];
}
ans[n] = total - pref[n - 1];
cout << "! ";
for (int i = 1; i <= n; i++) {
if (i > 1) cout << ' ';
cout << ans[i];
}
cout << endl; // 念のためflush
return 0;
}