#include <cstdio>
#include <vector>
#include <bits/stdc++.h>
#include "library.h"
// #include "debug_local.h"
using namespace std;
void Solve(int n) {
vector<int> edge[n + 1];
vector<int> old(n);
int old_answer = 0;
for (int i = 1; i <= n; i++) {
vector<int> nw = old;
nw[i - 1] = 1;
int new_answer = Query(nw);
// debug(old_answer, new_answer);
if (old_answer + 1 == new_answer) {
old_answer = new_answer;
old = nw;
continue;
}
int lo = 1, hi = i - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
vector<int> q(n);
for (int j = 1; j <= mid; j++) q[j - 1] = 1;
// debug(q);
int x = Query(q);
q[i - 1] = 1;
int y = Query(q);
// debug(x, q, y);
if (y > x) lo = mid + 1;
else hi = mid;
// debug(lo, hi);
}
// cout << lo << " " << i << endl;
edge[lo].push_back(i);
edge[i].push_back(lo);
if (new_answer < old_answer) {
lo = 1, hi = i - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
vector<int> q(n);
for (int j = 1; j <= mid; j++) q[j - 1] = 1;
int x = Query(q);
q[i - 1] = 1;
int y = Query(q);
if (x <= y) lo = mid + 1;
else hi = mid;
}
edge[lo].push_back(i);
edge[i].push_back(lo);
}
old_answer = new_answer;
old = nw;
}
int start;
for (int i = 1; i <= n; i++) {
if ((int) edge[i].size() <= 1) start = i;
}
vector<bool> vis(n + 1);
vector<int> ans;
while ((int) ans.size() < n) {
ans.push_back(start);
vis[start] = true;
for (int next : edge[start]) {
if (!vis[next]) {
start = next;
break;
}
}
}
Answer(ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
208 KB |
# of queries: 2854 |
2 |
Correct |
37 ms |
292 KB |
# of queries: 2821 |
3 |
Correct |
26 ms |
300 KB |
# of queries: 2974 |
4 |
Correct |
44 ms |
296 KB |
# of queries: 2968 |
5 |
Correct |
36 ms |
208 KB |
# of queries: 2954 |
6 |
Correct |
39 ms |
328 KB |
# of queries: 2964 |
7 |
Correct |
39 ms |
284 KB |
# of queries: 2998 |
8 |
Correct |
38 ms |
288 KB |
# of queries: 2841 |
9 |
Correct |
38 ms |
208 KB |
# of queries: 2997 |
10 |
Correct |
22 ms |
280 KB |
# of queries: 1751 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 1 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 12 |
15 |
Correct |
3 ms |
208 KB |
# of queries: 107 |
16 |
Correct |
4 ms |
208 KB |
# of queries: 235 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
208 KB |
# of queries: 2854 |
2 |
Correct |
37 ms |
292 KB |
# of queries: 2821 |
3 |
Correct |
26 ms |
300 KB |
# of queries: 2974 |
4 |
Correct |
44 ms |
296 KB |
# of queries: 2968 |
5 |
Correct |
36 ms |
208 KB |
# of queries: 2954 |
6 |
Correct |
39 ms |
328 KB |
# of queries: 2964 |
7 |
Correct |
39 ms |
284 KB |
# of queries: 2998 |
8 |
Correct |
38 ms |
288 KB |
# of queries: 2841 |
9 |
Correct |
38 ms |
208 KB |
# of queries: 2997 |
10 |
Correct |
22 ms |
280 KB |
# of queries: 1751 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 1 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 12 |
15 |
Correct |
3 ms |
208 KB |
# of queries: 107 |
16 |
Correct |
4 ms |
208 KB |
# of queries: 235 |
17 |
Correct |
294 ms |
336 KB |
# of queries: 19590 |
18 |
Correct |
249 ms |
336 KB |
# of queries: 19329 |
19 |
Correct |
274 ms |
344 KB |
# of queries: 19548 |
20 |
Correct |
265 ms |
336 KB |
# of queries: 18300 |
21 |
Correct |
230 ms |
440 KB |
# of queries: 17167 |
22 |
Correct |
296 ms |
336 KB |
# of queries: 19630 |
23 |
Correct |
306 ms |
336 KB |
# of queries: 19527 |
24 |
Correct |
142 ms |
316 KB |
# of queries: 9047 |
25 |
Correct |
230 ms |
456 KB |
# of queries: 19165 |
26 |
Correct |
251 ms |
336 KB |
# of queries: 17899 |
27 |
Correct |
115 ms |
312 KB |
# of queries: 9019 |
28 |
Correct |
232 ms |
452 KB |
# of queries: 16956 |
29 |
Correct |
234 ms |
448 KB |
# of queries: 16937 |
30 |
Correct |
233 ms |
344 KB |
# of queries: 16956 |