#include <cstdio>
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
void Solve(int N){
vector<int> M(N);
vector<int> res(N);
vector<deque<int>> curr;
vector<bool> rem(N+1,0);
curr.push_back({1});
int prev = 1;
M[0] = 1;
for(int i=2;i<=N;i++){
M[i-1] = 1;
int q = Query(M);
if(q > prev){
curr.push_back({i});
prev = q;
}else{
vector<int> side;
for(int c=0;c<(int)curr.size();c++){
if(rem[c])continue;
vector<int> m(N);
m[i-1] = 1;
for(auto cc:curr[c])m[cc-1] = 1;
if(Query(m) == 1)side.push_back(c);
}
vector<int> m(N);
m[i-1] = 1;
for(auto cc:curr[side[0]])m[cc-1] = 1;
bool pos = 0;
if(curr[side[0]].size() > 1){
m[curr[side[0]].back()-1] = 0;
int q = Query(m);
m[curr[side[0]].back()-1] = 1;
if(q == 1){
curr[side[0]].push_front(i);
}else{
pos = 1;
curr[side[0]].push_back(i);
}
}else{
curr[side[0]].push_front(i);
}
if((int)side.size() == 2){
curr.push_back(deque<int>());
rem[side[1]] = 1;
rem[side[0]] = 1;
int c = curr[side[1]].front(),d = curr[side[1]].back();
if(pos){
m[c-1] = 1;
q = Query(m);
for(auto cc:curr[side[0]])curr.back().push_back(cc);
if(q == 1){
for(auto cc:curr[side[1]])curr.back().push_back(cc);
}else
{
reverse(curr[side[1]].begin(),curr[side[1]].end());
for(auto cc:curr[side[1]])curr.back().push_back(cc);
}
}else{
m[d-1] = 1;
q = Query(m);
if(q == 1){
for(auto cc:curr[side[1]])curr.back().push_back(cc);
for(auto cc:curr[side[0]])curr.back().push_back(cc);
}else{
reverse(curr[side[1]].begin(),curr[side[1]].end());
for(auto cc:curr[side[1]])curr.back().push_back(cc);
for(auto cc:curr[side[0]])curr.back().push_back(cc);
}
}
curr[side[1]].clear();
curr[side[0]].clear();
prev--;
}
}
/*
for(int c=0;c<(int)curr.size();c++){
if(!rem[c]){
for(auto j:curr[c]){
cerr << j<<" ";
}
cerr << '\n';
}
}
cerr<<"out\n";*/
}
res = vector<int>(curr.back().begin(),curr.back().end());
Answer(res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
452 KB |
# of queries: 4635 |
2 |
Correct |
104 ms |
340 KB |
# of queries: 4835 |
3 |
Correct |
101 ms |
332 KB |
# of queries: 5106 |
4 |
Correct |
107 ms |
344 KB |
# of queries: 5241 |
5 |
Correct |
79 ms |
464 KB |
# of queries: 5130 |
6 |
Correct |
102 ms |
336 KB |
# of queries: 4995 |
7 |
Correct |
106 ms |
596 KB |
# of queries: 5144 |
8 |
Correct |
93 ms |
344 KB |
# of queries: 4563 |
9 |
Correct |
94 ms |
468 KB |
# of queries: 5329 |
10 |
Correct |
44 ms |
328 KB |
# of queries: 2210 |
11 |
Correct |
1 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
200 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 8 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 56 |
16 |
Correct |
3 ms |
200 KB |
# of queries: 159 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
452 KB |
# of queries: 4635 |
2 |
Correct |
104 ms |
340 KB |
# of queries: 4835 |
3 |
Correct |
101 ms |
332 KB |
# of queries: 5106 |
4 |
Correct |
107 ms |
344 KB |
# of queries: 5241 |
5 |
Correct |
79 ms |
464 KB |
# of queries: 5130 |
6 |
Correct |
102 ms |
336 KB |
# of queries: 4995 |
7 |
Correct |
106 ms |
596 KB |
# of queries: 5144 |
8 |
Correct |
93 ms |
344 KB |
# of queries: 4563 |
9 |
Correct |
94 ms |
468 KB |
# of queries: 5329 |
10 |
Correct |
44 ms |
328 KB |
# of queries: 2210 |
11 |
Correct |
1 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
200 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 8 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 56 |
16 |
Correct |
3 ms |
200 KB |
# of queries: 159 |
17 |
Runtime error |
513 ms |
456 KB |
Execution killed with signal 13 |
18 |
Halted |
0 ms |
0 KB |
- |