結果

問題 No.2124 Guess the Permutation
ユーザー みここみここ
提出日時 2022-12-11 20:49:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 75,832 KB
実行使用メモリ 25,220 KB
平均クエリ数 374.60
最終ジャッジ日時 2024-04-23 15:58:27
合計ジャッジ時間 2,063 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,812 KB
testcase_01 AC 23 ms
24,580 KB
testcase_02 AC 23 ms
25,220 KB
testcase_03 AC 24 ms
25,220 KB
testcase_04 AC 29 ms
25,220 KB
testcase_05 AC 29 ms
24,964 KB
testcase_06 AC 44 ms
25,220 KB
testcase_07 AC 56 ms
24,964 KB
testcase_08 AC 59 ms
25,064 KB
testcase_09 AC 59 ms
24,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0