結果
| 問題 |
No.2124 Guess the Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-11 20:49:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 1,055 bytes |
| コンパイル時間 | 676 ms |
| コンパイル使用メモリ | 71,508 KB |
| 最終ジャッジ日時 | 2025-02-09 09:46:09 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
cout << "?" << " " << 1 << " " << 2 << endl;
int s;
cin >> s;
cout << "?" << " " << 2 << " " << 3 << endl;
int t;
cin >> t;
if (n == 3)
{
int p[3] = {1, 2, 3};
do
{
if (p[0] + p[1] == s && p[1] + p[2] == t)
{
cout << "!"
<< " " << p[0] << " " << p[1] << " " << p[2] << endl;
return 0;
}
} while (next_permutation(p, p + 3));
}
cout << "?" << " " << 1 << " " << 3 << endl;
int u;
cin >> u;
int p[1005];
p[0] = u - t;
p[1] = s + t - u;
p[2] = u - s;
for (int i = 3; i < n - 1; i++)
{
int v;
cout << "?" << " " << 1 << " " << i + 1 << endl;
cin >> v;
p[i] = v - u;
u = v;
}
p[n - 1] = n * (n + 1) / 2 - u;
cout << "!";
for (int i = 0; i < n; i++)
{
cout << " " << p[i];
}
cout << endl;
}