#include "library.h"
#include <bits/stdc++.h>
using namespace std;
void Solve(int N) {
if (N == 1) {
Answer({1});
return;
}
if (N == 2) {
Answer({1, 2});
return;
}
vector<int> cc[N];
for (int i = 0; i < N; i++) {
cc[i].resize(N);
iota(cc[i].begin(), cc[i].end(), 0);
cc[i].erase(find(cc[i].begin(), cc[i].end(), i));
}
vector<int> adj[N];
auto findBest = [&](int i) {
int lo = 0, hi = cc[i].size();
while (lo < hi) {
int mid = lo + hi >> 1;
vector<int> vec(N);
for (int j = 0; j <= mid; j++) {
vec[cc[i][j]] = 1;
}
int q = Query(vec);
vec[i] = 1;
q - Query(vec) < 0 ? lo = mid + 1 : hi = mid;
}
if (lo == cc[i].size()) return -1;
int j = cc[i][lo];
adj[i].push_back(j);
adj[j].push_back(i);
cc[j].erase(find(cc[j].begin(), cc[j].end(), i));
cc[i].erase(find(cc[i].begin(), cc[i].end(), j));
return j;
};
for (int cur = 0; cur >= 0; cur = findBest(cur));
for (int cur = 0; cur >= 0; cur = findBest(cur));
for (int i = 0; i < N; i++) {
if (adj[i].size() < 2) {
vector<int> ans(N);
ans[0] = i;
for (int j = 1, x = adj[i][0]; j < N; j++) {
ans[j] = x;
for (int k : adj[x]) {
x = k == ans[j-1] ? x : k;
}
}
for (int &j : ans) {
j++;
}
Answer(ans);
return;
}
}
}
Compilation message
library.cpp: In lambda function:
library.cpp:26:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | int mid = lo + hi >> 1;
| ~~~^~~~
library.cpp:35:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (lo == cc[i].size()) return -1;
| ~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
336 KB |
# of queries: 2954 |
2 |
Correct |
34 ms |
336 KB |
# of queries: 2932 |
3 |
Correct |
34 ms |
464 KB |
# of queries: 3110 |
4 |
Correct |
28 ms |
464 KB |
# of queries: 3096 |
5 |
Correct |
34 ms |
468 KB |
# of queries: 3092 |
6 |
Correct |
29 ms |
464 KB |
# of queries: 3110 |
7 |
Correct |
35 ms |
464 KB |
# of queries: 3108 |
8 |
Correct |
42 ms |
336 KB |
# of queries: 2964 |
9 |
Correct |
39 ms |
464 KB |
# of queries: 3092 |
10 |
Correct |
24 ms |
336 KB |
# of queries: 1820 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 10 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 16 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 124 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 268 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
336 KB |
# of queries: 2954 |
2 |
Correct |
34 ms |
336 KB |
# of queries: 2932 |
3 |
Correct |
34 ms |
464 KB |
# of queries: 3110 |
4 |
Correct |
28 ms |
464 KB |
# of queries: 3096 |
5 |
Correct |
34 ms |
468 KB |
# of queries: 3092 |
6 |
Correct |
29 ms |
464 KB |
# of queries: 3110 |
7 |
Correct |
35 ms |
464 KB |
# of queries: 3108 |
8 |
Correct |
42 ms |
336 KB |
# of queries: 2964 |
9 |
Correct |
39 ms |
464 KB |
# of queries: 3092 |
10 |
Correct |
24 ms |
336 KB |
# of queries: 1820 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 10 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 16 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 124 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 268 |
17 |
Correct |
171 ms |
4276 KB |
# of queries: 19962 |
18 |
Correct |
225 ms |
4184 KB |
# of queries: 19718 |
19 |
Correct |
196 ms |
4400 KB |
# of queries: 19970 |
20 |
Correct |
206 ms |
3832 KB |
# of queries: 18692 |
21 |
Correct |
181 ms |
3480 KB |
# of queries: 17606 |
22 |
Correct |
227 ms |
4400 KB |
# of queries: 19970 |
23 |
Correct |
260 ms |
4264 KB |
# of queries: 19944 |
24 |
Correct |
93 ms |
1340 KB |
# of queries: 9252 |
25 |
Correct |
227 ms |
4228 KB |
# of queries: 19488 |
26 |
Correct |
221 ms |
3684 KB |
# of queries: 18284 |
27 |
Correct |
108 ms |
1360 KB |
# of queries: 9212 |
28 |
Correct |
260 ms |
4276 KB |
# of queries: 19968 |
29 |
Correct |
256 ms |
4280 KB |
# of queries: 19946 |
30 |
Correct |
225 ms |
4396 KB |
# of queries: 19968 |