#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 |
28 ms |
284 KB |
# of queries: 2854 |
2 |
Correct |
41 ms |
300 KB |
# of queries: 2821 |
3 |
Correct |
34 ms |
288 KB |
# of queries: 2974 |
4 |
Correct |
39 ms |
296 KB |
# of queries: 2968 |
5 |
Correct |
39 ms |
328 KB |
# of queries: 2954 |
6 |
Correct |
35 ms |
292 KB |
# of queries: 2964 |
7 |
Correct |
52 ms |
288 KB |
# of queries: 2998 |
8 |
Correct |
40 ms |
292 KB |
# of queries: 2841 |
9 |
Correct |
36 ms |
416 KB |
# of queries: 2997 |
10 |
Correct |
22 ms |
288 KB |
# of queries: 1751 |
11 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [5] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
284 KB |
# of queries: 2854 |
2 |
Correct |
41 ms |
300 KB |
# of queries: 2821 |
3 |
Correct |
34 ms |
288 KB |
# of queries: 2974 |
4 |
Correct |
39 ms |
296 KB |
# of queries: 2968 |
5 |
Correct |
39 ms |
328 KB |
# of queries: 2954 |
6 |
Correct |
35 ms |
292 KB |
# of queries: 2964 |
7 |
Correct |
52 ms |
288 KB |
# of queries: 2998 |
8 |
Correct |
40 ms |
292 KB |
# of queries: 2841 |
9 |
Correct |
36 ms |
416 KB |
# of queries: 2997 |
10 |
Correct |
22 ms |
288 KB |
# of queries: 1751 |
11 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [5] |
12 |
Halted |
0 ms |
0 KB |
- |