13712022-08-02 11:03:55mraronNomekopcpp14Accepted 100/1002.115s4468 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
1Accepted3ms1900 KiB
subtask210/10
2Accepted2ms1932 KiB
3Accepted2ms2124 KiB
subtask330/30
4Accepted4ms2324 KiB
5Accepted37ms2520 KiB
6Accepted37ms2592 KiB
7Accepted37ms2584 KiB
8Accepted4ms2716 KiB
9Accepted37ms2936 KiB
subtask420/20
10Accepted136ms2980 KiB
11Accepted145ms3236 KiB
12Accepted136ms3428 KiB
13Accepted135ms3496 KiB
subtask540/40
14Accepted2.063s4008 KiB
15Accepted2.115s3956 KiB
16Accepted1.825s3908 KiB
17Accepted1.567s3916 KiB
18Accepted2.065s4128 KiB
19Accepted2.049s4184 KiB
20Accepted2.068s4328 KiB
21Accepted2.045s4468 KiB