#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;
for(int i = 0; i < v.size(); i ++)
M[v[i]] = 1;
int A = Query(M);
M[cur] = 1;
int B = Query(M);
M[cur] = 0;
for(int i = 0; i < v.size(); i ++)
M[v[i]] = 0;
if(A < B) break;
int lo = 0, hi = v.size() - 1, rs;
while(lo <= hi){
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);
M[cur] = 0;
for(int i = 0; i <= md; i ++)
M[v[i]] = 0;
if(A >= B){
rs = v[md];
hi = md - 1;
} else
lo = md + 1;
}
cur = rs;
used[cur] = 1;
a[++ p1] = cur;
}
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;
for(int i = 0; i < v.size(); i ++)
M[v[i]] = 1;
int A = Query(M);
M[cur] = 1;
int B = Query(M);
M[cur] = 0;
for(int i = 0; i < v.size(); i ++)
M[v[i]] = 0;
if(A < B) break;
int lo = 0, hi = v.size() - 1, rs;
while(lo <= hi){
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);
M[cur] = 0;
for(int i = 0; i <= md; i ++)
M[v[i]] = 0;
if(A >= B){
rs = v[md];
hi = md - 1;
} else
lo = md + 1;
}
cur = rs;
used[cur] = 1;
b[++ p2] = cur;
}
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);
}
Compilation message
library.cpp: In function 'void Solve(int)':
library.cpp:19:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i ++)
~~^~~~~~~~~~
library.cpp:25:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i ++)
~~^~~~~~~~~~
library.cpp:60:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i ++)
~~^~~~~~~~~~
library.cpp:66:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i ++)
~~^~~~~~~~~~
library.cpp:89:21: warning: 'rs' may be used uninitialized in this function [-Wmaybe-uninitialized]
used[cur] = 1;
^
library.cpp:48:21: warning: 'rs' may be used uninitialized in this function [-Wmaybe-uninitialized]
used[cur] = 1;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
248 KB |
Output is correct |
2 |
Correct |
41 ms |
308 KB |
Output is correct |
3 |
Correct |
47 ms |
344 KB |
Output is correct |
4 |
Correct |
43 ms |
428 KB |
Output is correct |
5 |
Correct |
46 ms |
460 KB |
Output is correct |
6 |
Correct |
45 ms |
460 KB |
Output is correct |
7 |
Correct |
49 ms |
460 KB |
Output is correct |
8 |
Correct |
42 ms |
460 KB |
Output is correct |
9 |
Correct |
44 ms |
656 KB |
Output is correct |
10 |
Correct |
17 ms |
656 KB |
Output is correct |
11 |
Correct |
2 ms |
656 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
2 ms |
656 KB |
Output is correct |
14 |
Correct |
2 ms |
656 KB |
Output is correct |
15 |
Correct |
3 ms |
656 KB |
Output is correct |
16 |
Correct |
3 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
248 KB |
Output is correct |
2 |
Correct |
41 ms |
308 KB |
Output is correct |
3 |
Correct |
47 ms |
344 KB |
Output is correct |
4 |
Correct |
43 ms |
428 KB |
Output is correct |
5 |
Correct |
46 ms |
460 KB |
Output is correct |
6 |
Correct |
45 ms |
460 KB |
Output is correct |
7 |
Correct |
49 ms |
460 KB |
Output is correct |
8 |
Correct |
42 ms |
460 KB |
Output is correct |
9 |
Correct |
44 ms |
656 KB |
Output is correct |
10 |
Correct |
17 ms |
656 KB |
Output is correct |
11 |
Correct |
2 ms |
656 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
2 ms |
656 KB |
Output is correct |
14 |
Correct |
2 ms |
656 KB |
Output is correct |
15 |
Correct |
3 ms |
656 KB |
Output is correct |
16 |
Correct |
3 ms |
656 KB |
Output is correct |
17 |
Correct |
455 ms |
656 KB |
Output is correct |
18 |
Correct |
475 ms |
656 KB |
Output is correct |
19 |
Correct |
515 ms |
656 KB |
Output is correct |
20 |
Correct |
457 ms |
656 KB |
Output is correct |
21 |
Correct |
401 ms |
656 KB |
Output is correct |
22 |
Correct |
468 ms |
656 KB |
Output is correct |
23 |
Correct |
473 ms |
656 KB |
Output is correct |
24 |
Correct |
203 ms |
656 KB |
Output is correct |
25 |
Correct |
419 ms |
656 KB |
Output is correct |
26 |
Correct |
403 ms |
656 KB |
Output is correct |
27 |
Correct |
161 ms |
656 KB |
Output is correct |
28 |
Correct |
391 ms |
656 KB |
Output is correct |
29 |
Correct |
418 ms |
656 KB |
Output is correct |
30 |
Correct |
428 ms |
656 KB |
Output is correct |