-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlife.cpp
60 lines (52 loc) · 1.15 KB
/
life.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
function<int(int, int, bool)> query = [&](int x, int v, bool down) {
if (v > n) return 0;
cout << "? ";
for (int i = 0; i < n; i++) {
if ((i == x) ^ down)
cout << v + 1 << " ";
else
cout << "1 ";
}
cout << endl;
cout.flush();
int k;
cin >> k;
return k;
};
vi ans(n);
int last = 0;
int x = 0;
vector<int> res;
res.push_back(0);
while ((last = query(0, ++x, false))) {
res.push_back(last-1);
}
x = 0;
while ((last = query(0, ++x, true))) {
res.insert(res.begin(), last-1);
}
// x + p_i == n
// p_i == n - x
for (int i = 0; i < n; i++) {
ans[res[i]] = i + 1;
}
cout << "! ";
for (int i = 0; i < n; i++) {
cout << ans[i] << " ";
}
cout << endl;
cout.flush();
return 0;
}