88042024-01-31 09:34:09Error42Nomekopcpp17Accepted 100/1001.557s4416 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;

struct nomekop {
    ll pos, delta_attack, companion;
    bool done;
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n;
    cin >> n;

    vector<ll> a(n);
    for (ll& x : a)
        cin >> x;

    // all same
    if (count(a.begin(), a.end(), a[0]) == n) {
        cout << "!";

        for (int i = 0; i < n; i++)
            cout << " " << a[i];

        cout << endl;

        return 0;
    }

    cout << "?";

    for (int i = 0; i < n; i++)
        cout << " " << a[i];

    cout << endl;

    ll baseline;
    cin >> baseline;

    vector<nomekop> opponents(n);

    auto const test_against = [&](int const f) {
        for (int i = 0; i < n; i++) {
            if (i == f || a[i] == a[f] || opponents[i].done)
                continue;

            cout << "?";

            for (int j = 0; j < n; j++) {
                cout << " ";
                if (j == i)
                    cout << a[f];
                else if (j == f)
                    cout << a[i];
                else
                    cout << a[j];
            }

            cout << endl;

            ll cur;
            cin >> cur;

            ll delta = cur - baseline;

            opponents[i].pos = i;
            opponents[i].delta_attack = delta / (a[f] - a[i]) + opponents[f].delta_attack;

            opponents[i].done = true;
        }
    };

    test_against(0);

    for (int i = 1; i < n; i++) {
        if (a[i] != a[0]) {
            test_against(i);
            break;
        }
    }

    sort(opponents.begin(), opponents.end(), [&](nomekop const& a, nomekop const& b) {
        return a.delta_attack < b.delta_attack;
    });

    sort(a.begin(), a.end());

    for (int i = 0; i < n; i++)
        opponents[i].companion = a[i];

    sort(opponents.begin(), opponents.end(), [&](nomekop const& a, nomekop const& b) {
        return a.pos < b.pos;
    });

    cout << "!";

    for (nomekop const& x : opponents)
        cout << " " << x.companion;
    cout << endl;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
subtask210/10
2Accepted3ms2060 KiB
3Accepted3ms2136 KiB
subtask330/30
4Accepted4ms2336 KiB
5Accepted29ms2700 KiB
6Accepted29ms2784 KiB
7Accepted30ms2760 KiB
8Accepted4ms2636 KiB
9Accepted29ms3008 KiB
subtask420/20
10Accepted104ms3256 KiB
11Accepted104ms3260 KiB
12Accepted104ms3456 KiB
13Accepted104ms3708 KiB
subtask540/40
14Accepted1.557s4012 KiB
15Accepted1.557s3928 KiB
16Accepted1.373s3952 KiB
17Accepted1.195s4016 KiB
18Accepted1.526s3912 KiB
19Accepted1.519s4132 KiB
20Accepted1.523s4296 KiB
21Accepted1.514s4416 KiB