#include "library.h"
#include <bits/stdc++.h>
using namespace std;
void Solve(int N) {
if (N == 1) {
Answer(vector<int>{1});
return;
}
if (N == 2) {
Answer(vector<int>{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));
}
int ae[N], s = 0;
for (int i = 0; i < N; i++) {
vector<int> vec(N, 1);
vec[i] = 0;
ae[i] = Query(vec) < 2;
s = ae[i] ? s : i;
}
vector<int> adj[N];
auto findBest = [&](int i) {
int lo = 0, hi = cc[i].size()-1;
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 = s; cur >= 0 && !ae[cur]; cur = findBest(cur));
for (int cur = s; cur >= 0 && !ae[cur]; 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:34:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int mid = lo + hi >> 1;
| ~~~^~~~
library.cpp:43:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if (lo == cc[i].size()) return -1;
| ~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
336 KB |
# of queries: 3132 |
2 |
Correct |
35 ms |
436 KB |
# of queries: 3105 |
3 |
Correct |
36 ms |
336 KB |
# of queries: 3268 |
4 |
Correct |
38 ms |
464 KB |
# of queries: 3278 |
5 |
Correct |
30 ms |
468 KB |
# of queries: 3272 |
6 |
Correct |
35 ms |
464 KB |
# of queries: 3284 |
7 |
Correct |
44 ms |
464 KB |
# of queries: 3272 |
8 |
Correct |
35 ms |
452 KB |
# of queries: 3123 |
9 |
Correct |
36 ms |
464 KB |
# of queries: 3241 |
10 |
Correct |
22 ms |
336 KB |
# of queries: 1921 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
208 KB |
# of queries: 5 |
14 |
Correct |
0 ms |
208 KB |
# of queries: 12 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 125 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 277 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
336 KB |
# of queries: 3132 |
2 |
Correct |
35 ms |
436 KB |
# of queries: 3105 |
3 |
Correct |
36 ms |
336 KB |
# of queries: 3268 |
4 |
Correct |
38 ms |
464 KB |
# of queries: 3278 |
5 |
Correct |
30 ms |
468 KB |
# of queries: 3272 |
6 |
Correct |
35 ms |
464 KB |
# of queries: 3284 |
7 |
Correct |
44 ms |
464 KB |
# of queries: 3272 |
8 |
Correct |
35 ms |
452 KB |
# of queries: 3123 |
9 |
Correct |
36 ms |
464 KB |
# of queries: 3241 |
10 |
Correct |
22 ms |
336 KB |
# of queries: 1921 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
208 KB |
# of queries: 5 |
14 |
Correct |
0 ms |
208 KB |
# of queries: 12 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 125 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 277 |
17 |
Runtime error |
264 ms |
4512 KB |
Execution killed with signal 13 |
18 |
Halted |
0 ms |
0 KB |
- |