#include <cstdio>
#include <vector>
#include "library.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
vector<int> adj[MAXN];
vector<int> res;
int vs[MAXN];
void dfs(int u , int n){
vs[u] = 1;
assert(1 <= u and u <= n);
res.push_back(u);
for(auto x : adj[u]) if(vs[x] == 0) dfs(x , n);
}
void Solve(int n)
{
int lst = -1;
int cur = 1;
int cnt = 0;
while(cnt < n - 1){
vector<int> t;
for(int j = 1 ; j <= n ; j++){
if(cur == j or j == lst) continue;
t.push_back(j);
}
int l = 0 , r = t.size()-1;
int res = -1;
while(l <= r){
int mid = l + r >> 1;
vector<int> m(n);
for(int j = l ; j <=mid ; j++) m[t[j] - 1] = 1;
int c1 = Query(m);
m[cur-1] = 1;
int c2 = Query(m);
if(c2 <= c1) res = mid , r = mid-1;
else l = mid+1;
}
if(res == -1){
cur = 1;
lst = adj[1][0];
}else{
res = t[res];
adj[cur].push_back(res);
adj[res].push_back(cur);
lst = cur , cur = res, cnt++;
}
}
for(int i = 1; i <= n ; i++){
if(adj[i].size() == 1){
dfs(i , n);
break;
}
}
Answer(res);
}
Compilation message
library.cpp: In function 'void Solve(int)':
library.cpp:32:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
344 KB |
# of queries: 2942 |
2 |
Correct |
28 ms |
592 KB |
# of queries: 2920 |
3 |
Correct |
27 ms |
600 KB |
# of queries: 3104 |
4 |
Correct |
34 ms |
728 KB |
# of queries: 3084 |
5 |
Correct |
28 ms |
464 KB |
# of queries: 3100 |
6 |
Correct |
49 ms |
488 KB |
# of queries: 3094 |
7 |
Correct |
26 ms |
592 KB |
# of queries: 3080 |
8 |
Correct |
31 ms |
484 KB |
# of queries: 2960 |
9 |
Correct |
31 ms |
492 KB |
# of queries: 3068 |
10 |
Correct |
17 ms |
592 KB |
# of queries: 1806 |
11 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [4] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
344 KB |
# of queries: 2942 |
2 |
Correct |
28 ms |
592 KB |
# of queries: 2920 |
3 |
Correct |
27 ms |
600 KB |
# of queries: 3104 |
4 |
Correct |
34 ms |
728 KB |
# of queries: 3084 |
5 |
Correct |
28 ms |
464 KB |
# of queries: 3100 |
6 |
Correct |
49 ms |
488 KB |
# of queries: 3094 |
7 |
Correct |
26 ms |
592 KB |
# of queries: 3080 |
8 |
Correct |
31 ms |
484 KB |
# of queries: 2960 |
9 |
Correct |
31 ms |
492 KB |
# of queries: 3068 |
10 |
Correct |
17 ms |
592 KB |
# of queries: 1806 |
11 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [4] |
12 |
Halted |
0 ms |
0 KB |
- |