#include <bits/stdc++.h>
#include "library.h"
//~ #include "grader.cpp"
using namespace std;
void Solve(int n){
if(n == 1){
vector<int> ans = {1};
Answer(ans);
return;
}
vector<vector<int>> v(n);
for(int i=0;i<n;i++){
if(v[i].size() == 2)continue;
vector<int> ask(n, 0);
ask[i] = 1;
for(int j=i+1;j<n;j++){
if(v[j].size() == 2 || v[i].size() == 2)continue;
ask[j] = 1;
if(Query(ask) == 1)v[i].push_back(j), v[j].push_back(i);
ask[j] = 0;
}
}
//~ for(int i=0;i<n;i++){for(auto x : v[i])cout << x << ' ';cout << '\n';}
vector<bool> used(n);
vector<int> ans;
int u=-1;
for(int i=0;i<n;i++){
if(v[i].size() == 1){
u = i;break;
}
}
assert(u != -1);
while(true){
bool ch = false;
used[u] = true;
ans.push_back(u+1);
for(auto to : v[u]){
if(!used[to]){
ch=true;
u=to;
}
}if(!ch)break;
}
Answer(ans);
return;
}
/*
5
4 2 5 3 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
492 KB |
# of queries: 8277 |
2 |
Correct |
103 ms |
492 KB |
# of queries: 8239 |
3 |
Correct |
127 ms |
364 KB |
# of queries: 9230 |
4 |
Correct |
110 ms |
508 KB |
# of queries: 9178 |
5 |
Correct |
136 ms |
364 KB |
# of queries: 9216 |
6 |
Correct |
149 ms |
364 KB |
# of queries: 8800 |
7 |
Correct |
126 ms |
492 KB |
# of queries: 9069 |
8 |
Correct |
118 ms |
620 KB |
# of queries: 8272 |
9 |
Correct |
134 ms |
364 KB |
# of queries: 9253 |
10 |
Correct |
65 ms |
364 KB |
# of queries: 3883 |
11 |
Correct |
0 ms |
492 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
364 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
364 KB |
# of queries: 3 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 5 |
15 |
Correct |
2 ms |
364 KB |
# of queries: 57 |
16 |
Correct |
3 ms |
364 KB |
# of queries: 210 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
492 KB |
# of queries: 8277 |
2 |
Correct |
103 ms |
492 KB |
# of queries: 8239 |
3 |
Correct |
127 ms |
364 KB |
# of queries: 9230 |
4 |
Correct |
110 ms |
508 KB |
# of queries: 9178 |
5 |
Correct |
136 ms |
364 KB |
# of queries: 9216 |
6 |
Correct |
149 ms |
364 KB |
# of queries: 8800 |
7 |
Correct |
126 ms |
492 KB |
# of queries: 9069 |
8 |
Correct |
118 ms |
620 KB |
# of queries: 8272 |
9 |
Correct |
134 ms |
364 KB |
# of queries: 9253 |
10 |
Correct |
65 ms |
364 KB |
# of queries: 3883 |
11 |
Correct |
0 ms |
492 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
364 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
364 KB |
# of queries: 3 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 5 |
15 |
Correct |
2 ms |
364 KB |
# of queries: 57 |
16 |
Correct |
3 ms |
364 KB |
# of queries: 210 |
17 |
Runtime error |
412 ms |
364 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
18 |
Halted |
0 ms |
0 KB |
- |