28452023-01-29 19:24:39VMGoJoNomekopcpp14Accepted 100/1002.065s4840 KiB
#include <bits/stdc++.h>
#include <cassert>
#include <signal.h>

#define N_MAX 4000

using namespace std;

int N;
int A[N_MAX + 5];
int D[N_MAX + 5];
int P[N_MAX + 5], ans[N_MAX + 5];

bool cmp(int a, int b) { return D[a] < D[b]; }

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    sort(A + 1, A + N + 1);

    long long ide;

    cout << "? ";
    for (int i = 1; i <= N; i++) {
        cout << A[i] << " ";
    }
    cout.flush();
    cin >> ide;

    bool first = true;
    int pos = -1;
    for (int i = 2; i <= N; i++) {
        if (A[i] != A[1]) {
            swap(A[i], A[1]);
            cout << "? ";
            for (int j = 1; j <= N; j++) {
                cout << A[j] << " ";
            }
            cout.flush();
            long long query;
            cin >> query;
            D[i] = (ide - query) / (A[1] - A[i]);
            swap(A[i], A[1]);
            if (first) {
                first = false;
                pos = i;
            }
        }
    }

    for (int i = 2; i < pos; i++) {
        swap(A[i], A[pos]);
        cout << "? ";
        for (int j = 1; j <= N; j++) {
            cout << A[j] << " ";
        }
        cout.flush();
        long long query;
        cin >> query;
        int dif = (ide - query) / (A[pos] - A[i]);
        D[i] = dif + D[pos];
        swap(A[i], A[pos]);
    }

    for (int i = 1; i <= N; i++) {
        P[i] = i;
    }
    sort(P + 1, P + N + 1, cmp);

    for (int i = 1; i <= N; i++) {
        ans[P[i]] = A[i];
    }

    cout << "! ";
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << " ";
    }
    cout.flush();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1896 KiB
subtask210/10
2Accepted2ms2056 KiB
3Accepted2ms2140 KiB
subtask330/30
4Accepted4ms2340 KiB
5Accepted37ms2420 KiB
6Accepted37ms2648 KiB
7Accepted37ms2764 KiB
8Accepted4ms2956 KiB
9Accepted37ms3160 KiB
subtask420/20
10Accepted136ms3172 KiB
11Accepted136ms3504 KiB
12Accepted137ms3584 KiB
13Accepted141ms3584 KiB
subtask540/40
14Accepted2.065s3892 KiB
15Accepted2.062s4032 KiB
16Accepted1.824s4084 KiB
17Accepted1.577s4316 KiB
18Accepted2.061s4332 KiB
19Accepted2.063s4356 KiB
20Accepted2.062s4752 KiB
21Accepted2.025s4840 KiB