#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define dforn(i, n) for(int i=n-1; i>=0; --i)
#define PB push_back
const int MAXN=110;
int n, reply;
bool vis[MAXN], blocked[MAXN];
vector<int> arr, rev, g[MAXN], net[MAXN], net_rev[MAXN], ord, reach;
vector<int> inv(vector<int>& per){
vector<int> ret(per.size());
forn(i, per.size()) ret[per[i]]=i;
return ret;
}
void dfs(int v){
vis[v]=true;
for(int to:g[v]) if(!vis[to]) dfs(to);
ord.PB(v);
}
void dfs2(int v, vector<int>* gr){
blocked[v]=true;
for(int to:gr[v]) if(!blocked[to]) dfs2(to, gr);
reach.PB(v);
}
vector<int> opt(vector<int> v, vector<int>* gr){
if(v.size()<=1) return v;
auto itr = min_element(v.begin(), v.end());
forn(i, n) blocked[i]=true;
for(auto el:v) blocked[el]=false;
reach.clear();
dfs2(*itr, gr);
for(int el:v) blocked[el]=false;
for(int re:reach) blocked[re]=true;
vector<int> l, r;
for(int el:v){
if(el==*itr) continue;
if(blocked[el]) r.PB(el);
else l.PB(el);
}
vector<int> lv = opt(l, gr);
vector<int> rv = opt(r, gr);
lv.PB(*itr);
lv.insert(lv.end(), rv.begin(), rv.end());
return lv;
}
int main(){
scanf("%d", &n);
arr.resize(n);
forn(i, n) scanf("%d", &arr[i]), --arr[i];
rev = inv(arr);
dforn(i, n){
forsn(j, i+1, n) g[i].PB(j);
forsn(j, i+1, n){
g[i].erase(find(g[i].begin(), g[i].end(), j));
forsn(k, i, n) vis[k]=false;
forsn(k, i, n) if(!vis[k]) dfs(k);
reverse(ord.begin(), ord.end());
vector<int> cr(n);
forn(k, n) cr[k]=rev[k<i? k : ord[k-i]];
vector<int> ask = inv(cr);
printf("query");
forn(k, n) printf(" %d", ask[k]+1);
printf("\n");
fflush(stdout);
scanf("%d", &reply);
if(!reply) g[i].PB(j);
ord.clear();
}
}
vector<int> alln;
forn(i, n) alln.PB(i);
forn(v, n) for(int to:g[v]) net[rev[v]].PB(rev[to]), net_rev[rev[to]].PB(rev[v]);
vector<int> ans1 = opt(alln, net_rev);
reverse(ans1.begin(), ans1.end());
vector<int> ans2 = opt(alln, net);
vector<int> ret1 = inv(ans1), ret2 = inv(ans2);
printf("end\n");
forn(i, n) printf("%d ", ret1[i]+1);
printf("\n");
forn(i, n) printf("%d ", ret2[i]+1);
printf("\n");
fflush(stdout);
}
Compilation message
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
zagonetka.cpp:58:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | forn(i, n) scanf("%d", &arr[i]), --arr[i];
| ~~~~~^~~~~~~~~~~~~~~
zagonetka.cpp:74:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | scanf("%d", &reply);
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
208 KB |
Output is correct |
2 |
Correct |
30 ms |
304 KB |
Output is correct |
3 |
Correct |
34 ms |
300 KB |
Output is correct |
4 |
Correct |
38 ms |
340 KB |
Output is correct |
5 |
Correct |
8 ms |
304 KB |
Output is correct |
6 |
Correct |
32 ms |
416 KB |
Output is correct |
7 |
Correct |
5 ms |
208 KB |
Output is correct |
8 |
Correct |
8 ms |
208 KB |
Output is correct |
9 |
Correct |
28 ms |
292 KB |
Output is correct |
10 |
Correct |
10 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
208 KB |
Output is correct |
2 |
Correct |
2 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
312 KB |
Output is correct |
4 |
Correct |
5 ms |
308 KB |
Output is correct |
5 |
Correct |
5 ms |
208 KB |
Output is correct |
6 |
Correct |
6 ms |
312 KB |
Output is correct |
7 |
Correct |
4 ms |
308 KB |
Output is correct |
8 |
Correct |
8 ms |
304 KB |
Output is correct |
9 |
Correct |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
308 KB |
Output is correct |
11 |
Correct |
5 ms |
316 KB |
Output is correct |
12 |
Correct |
7 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
324 KB |
Output is correct |
2 |
Correct |
88 ms |
316 KB |
Output is correct |
3 |
Correct |
67 ms |
328 KB |
Output is correct |
4 |
Correct |
71 ms |
312 KB |
Output is correct |
5 |
Correct |
64 ms |
308 KB |
Output is correct |
6 |
Correct |
100 ms |
300 KB |
Output is correct |
7 |
Correct |
74 ms |
308 KB |
Output is correct |
8 |
Correct |
77 ms |
328 KB |
Output is correct |
9 |
Correct |
90 ms |
336 KB |
Output is correct |
10 |
Correct |
70 ms |
304 KB |
Output is correct |
11 |
Correct |
77 ms |
312 KB |
Output is correct |
12 |
Correct |
59 ms |
304 KB |
Output is correct |
13 |
Correct |
82 ms |
304 KB |
Output is correct |
14 |
Correct |
62 ms |
304 KB |
Output is correct |
15 |
Correct |
84 ms |
328 KB |
Output is correct |
16 |
Correct |
84 ms |
304 KB |
Output is correct |