#include <bits/stdc++.h>
//#include "grader.cpp"
#include "library.h"
#define pb push_back
#define ok cerr << "OK\n";
using namespace std;
const int NN = 1e5 + 7;
int used[NN];
void Solve(int N) {
vector < int > M(N, 1);
int n = N;
vector < int > ans, v1, v2;
int cnt = 0, qq;
int q1 = n;
while (cnt < n - 1 && q1--) {
for (int i = 0; i < n && cnt < n - 1; i++) {
if (used[i]) continue;
M[i] = 0;
qq = Query(M);
M[i] = 1;
if (qq == 1) {
if (v1.empty()) {
v1.pb(i);
} else {
M[v1.back()] = 1;
M[i] = 0;
qq = Query(M);
M[v1.back()] = 0;
if (qq == 1) {
v2.pb(i);
} else {
v1.pb(i);
}
}
used[i] = 1;
cnt++;
M[i] = 0;
}
}
if (!(cnt < n - 1)) break;
for (int i = n - 1; i >= 0 && cnt < n - 1; i--) {
if (used[i]) continue;
M[i] = 0;
qq = Query(M);
M[i] = 1;
if (qq == 1) {
if (v1.empty()) {
v1.pb(i);
} else {
M[v1.back()] = 1;
M[i] = 0;
qq = Query(M);
M[v1.back()] = 0;
if (qq == 1) {
v2.pb(i);
} else {
v1.pb(i);
}
}
used[i] = 1;
cnt++;
M[i] = 0;
}
}
}
if (n > 200) {
assert(0);
}
for (int i = 0; i < n; i++) {
if (!used[i]) v1.pb(i);
}
for (int to : v1) {
ans.pb(to + 1);
}
for (int i = (int)v2.size() - 1; i >= 0; i--) {
ans.pb(v2[i] + 1);
}
Answer(ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
396 KB |
Output is correct |
2 |
Correct |
92 ms |
440 KB |
Output is correct |
3 |
Correct |
106 ms |
440 KB |
Output is correct |
4 |
Correct |
94 ms |
448 KB |
Output is correct |
5 |
Correct |
98 ms |
504 KB |
Output is correct |
6 |
Correct |
98 ms |
504 KB |
Output is correct |
7 |
Correct |
106 ms |
560 KB |
Output is correct |
8 |
Correct |
91 ms |
564 KB |
Output is correct |
9 |
Correct |
105 ms |
564 KB |
Output is correct |
10 |
Correct |
43 ms |
564 KB |
Output is correct |
11 |
Correct |
1 ms |
564 KB |
Output is correct |
12 |
Correct |
2 ms |
572 KB |
Output is correct |
13 |
Correct |
2 ms |
572 KB |
Output is correct |
14 |
Correct |
2 ms |
572 KB |
Output is correct |
15 |
Correct |
2 ms |
572 KB |
Output is correct |
16 |
Correct |
3 ms |
572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
396 KB |
Output is correct |
2 |
Correct |
92 ms |
440 KB |
Output is correct |
3 |
Correct |
106 ms |
440 KB |
Output is correct |
4 |
Correct |
94 ms |
448 KB |
Output is correct |
5 |
Correct |
98 ms |
504 KB |
Output is correct |
6 |
Correct |
98 ms |
504 KB |
Output is correct |
7 |
Correct |
106 ms |
560 KB |
Output is correct |
8 |
Correct |
91 ms |
564 KB |
Output is correct |
9 |
Correct |
105 ms |
564 KB |
Output is correct |
10 |
Correct |
43 ms |
564 KB |
Output is correct |
11 |
Correct |
1 ms |
564 KB |
Output is correct |
12 |
Correct |
2 ms |
572 KB |
Output is correct |
13 |
Correct |
2 ms |
572 KB |
Output is correct |
14 |
Correct |
2 ms |
572 KB |
Output is correct |
15 |
Correct |
2 ms |
572 KB |
Output is correct |
16 |
Correct |
3 ms |
572 KB |
Output is correct |
17 |
Execution timed out |
2033 ms |
588 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |