#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
void Solve(int N){
vector <int> res(N), M(N), used(N), a(N), b(N);
int cur = 0, p1 = 0;
a[0] = 0;
b[0] = 0;
used[0] = 1;
while(1){
vector <int> v;
for(int i = 0; i < N; i ++)
if(!used[i])
v.emplace_back(i);
if(!v.size()) break;
int lo = 0, hi = v.size() - 1;
while(hi - lo > 1){
int md = (lo + hi) >> 1;
for(int i = 0; i <= md; i ++){
M[v[i]] = 1;
}
int A = Query(M);
M[cur] = 1;
int B = Query(M);
if(A >= B)
hi = md;
else
lo = md;
M[cur] = 0;
for(int i = 0; i <= md; i ++)
M[v[i]] = 0;
}
for(int i = 0; i <= lo; i ++)
M[v[i]] = 1;
int A = Query(M);
M[cur] = 1;
int B = Query(M);
if(A == B) hi = lo;
M[v[hi]] = 1;
M[cur] = 0;
A = Query(M);
M[cur] = 1;
B = Query(M);
M[cur] = 0;
for(int i = 0; i <= hi; i ++)
M[v[i]] = 0;
if(A < B) break;
used[v[hi]] = 1;
a[++ p1] = v[hi];
cur = v[hi];
}
cur = 0;
int p2 = 0;
while(1){
vector <int> v;
for(int i = 0; i < N; i ++)
if(!used[i])
v.emplace_back(i);
if(!v.size()) break;
int lo = 0, hi = v.size() - 1;
while(hi - lo > 1){
int md = (lo + hi) >> 1;
for(int i = 0; i <= md; i ++){
M[v[i]] = 1;
}
int A = Query(M);
M[cur] = 1;
int B = Query(M);
if(A >= B)
hi = md;
else
lo = md;
M[cur] = 0;
for(int i = 0; i <= md; i ++)
M[v[i]] = 0;
}
for(int i = 0; i <= lo; i ++)
M[v[i]] = 1;
int A = Query(M);
M[cur] = 1;
int B = Query(M);
if(A == B) hi = lo;
M[v[hi]] = 1;
M[cur] = 0;
A = Query(M);
M[cur] = 1;
B = Query(M);
M[cur] = 0;
for(int i = 0; i <= hi; i ++)
M[v[i]] = 0;
if(A < B) break;
used[v[hi]] = 1;
b[++ p2] = v[hi];
cur = v[hi];
}
int ps = 0;
for(int i = p2; i > 0; i --){
res[ps ++] = b[i] + 1;
}
for(int i = 0; i <= p1; i ++){
res[ps ++] = a[i] + 1;
}
Answer(res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
248 KB |
Output is correct |
2 |
Correct |
48 ms |
436 KB |
Output is correct |
3 |
Correct |
51 ms |
496 KB |
Output is correct |
4 |
Correct |
49 ms |
496 KB |
Output is correct |
5 |
Correct |
53 ms |
572 KB |
Output is correct |
6 |
Correct |
49 ms |
572 KB |
Output is correct |
7 |
Correct |
51 ms |
572 KB |
Output is correct |
8 |
Correct |
32 ms |
572 KB |
Output is correct |
9 |
Correct |
50 ms |
572 KB |
Output is correct |
10 |
Correct |
31 ms |
572 KB |
Output is correct |
11 |
Correct |
1 ms |
572 KB |
Output is correct |
12 |
Correct |
2 ms |
572 KB |
Output is correct |
13 |
Correct |
2 ms |
572 KB |
Output is correct |
14 |
Correct |
2 ms |
572 KB |
Output is correct |
15 |
Correct |
4 ms |
572 KB |
Output is correct |
16 |
Correct |
5 ms |
572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
248 KB |
Output is correct |
2 |
Correct |
48 ms |
436 KB |
Output is correct |
3 |
Correct |
51 ms |
496 KB |
Output is correct |
4 |
Correct |
49 ms |
496 KB |
Output is correct |
5 |
Correct |
53 ms |
572 KB |
Output is correct |
6 |
Correct |
49 ms |
572 KB |
Output is correct |
7 |
Correct |
51 ms |
572 KB |
Output is correct |
8 |
Correct |
32 ms |
572 KB |
Output is correct |
9 |
Correct |
50 ms |
572 KB |
Output is correct |
10 |
Correct |
31 ms |
572 KB |
Output is correct |
11 |
Correct |
1 ms |
572 KB |
Output is correct |
12 |
Correct |
2 ms |
572 KB |
Output is correct |
13 |
Correct |
2 ms |
572 KB |
Output is correct |
14 |
Correct |
2 ms |
572 KB |
Output is correct |
15 |
Correct |
4 ms |
572 KB |
Output is correct |
16 |
Correct |
5 ms |
572 KB |
Output is correct |
17 |
Incorrect |
541 ms |
588 KB |
Wrong Answer [3] |
18 |
Halted |
0 ms |
0 KB |
- |