#include "library.h"
#include <bits/stdc++.h>
using namespace std;
#define isz(a) (int)(a).size()
void Solve(int N){
if (N == 1){
Answer({1});
return;
}
if (N == 2){
Answer({1, 2});
return;
}
vector <int> p(N);
for (int i = 0; i < N; i++){
vector <int> arr = {};
for (int j = 0; j < N; j++)
if (j == i) arr.push_back(0); else arr.push_back(1);
if (Query(arr) == 1){
p[0] = i;
break;
}
}
for (int i = 0; i < N; i++){
if (i == p[0]) continue;
vector <int> arr = {};
for (int j = 0; j < N; j++)
if (j == p[0] || j == i) arr.push_back(1); else arr.push_back(0);
if (Query(arr) == 1){
p[1] = i;
break;
}
}
bool mark[N];
memset(mark, 0, sizeof(mark));
mark[p[0]] = mark[p[1]] = 1;
for (int i = 2; i < N; i++){
vector <int> rem = {};
for (int j = 0; j < N; j++)
if (!mark[j]) rem.push_back(j);
int l = 0, r = isz(rem)-2, res = isz(rem)-1;
while (l <= r){
int mid = (l+r)/2;
vector <int> arr(N, 0);
for (int j = 0; j < i; j++) arr[p[j]] = 1;
for (int j = 0; j <= mid; j++) arr[rem[j]] = 1;
int x = Query(arr), y;
arr[p[i-1]] = 0;
y = Query(arr);
if (x < y){
res = mid;
r = mid-1;
}
else l = mid+1;
}
p[i] = rem[res];
mark[p[i]] = 1;
}
for (int i = 0; i < N; i++) p[i]++;
Answer(p);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
344 KB |
# of queries: 2367 |
2 |
Correct |
32 ms |
344 KB |
# of queries: 2570 |
3 |
Correct |
23 ms |
344 KB |
# of queries: 2668 |
4 |
Correct |
25 ms |
344 KB |
# of queries: 2740 |
5 |
Correct |
30 ms |
344 KB |
# of queries: 2600 |
6 |
Correct |
26 ms |
344 KB |
# of queries: 2726 |
7 |
Correct |
26 ms |
344 KB |
# of queries: 2708 |
8 |
Correct |
24 ms |
344 KB |
# of queries: 2575 |
9 |
Correct |
25 ms |
344 KB |
# of queries: 2662 |
10 |
Correct |
14 ms |
344 KB |
# of queries: 1534 |
11 |
Correct |
0 ms |
344 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
344 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
344 KB |
# of queries: 3 |
14 |
Correct |
0 ms |
344 KB |
# of queries: 5 |
15 |
Correct |
1 ms |
344 KB |
# of queries: 79 |
16 |
Correct |
3 ms |
344 KB |
# of queries: 192 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
344 KB |
# of queries: 2367 |
2 |
Correct |
32 ms |
344 KB |
# of queries: 2570 |
3 |
Correct |
23 ms |
344 KB |
# of queries: 2668 |
4 |
Correct |
25 ms |
344 KB |
# of queries: 2740 |
5 |
Correct |
30 ms |
344 KB |
# of queries: 2600 |
6 |
Correct |
26 ms |
344 KB |
# of queries: 2726 |
7 |
Correct |
26 ms |
344 KB |
# of queries: 2708 |
8 |
Correct |
24 ms |
344 KB |
# of queries: 2575 |
9 |
Correct |
25 ms |
344 KB |
# of queries: 2662 |
10 |
Correct |
14 ms |
344 KB |
# of queries: 1534 |
11 |
Correct |
0 ms |
344 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
344 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
344 KB |
# of queries: 3 |
14 |
Correct |
0 ms |
344 KB |
# of queries: 5 |
15 |
Correct |
1 ms |
344 KB |
# of queries: 79 |
16 |
Correct |
3 ms |
344 KB |
# of queries: 192 |
17 |
Correct |
235 ms |
344 KB |
# of queries: 18495 |
18 |
Correct |
211 ms |
344 KB |
# of queries: 18249 |
19 |
Correct |
220 ms |
344 KB |
# of queries: 17590 |
20 |
Correct |
201 ms |
344 KB |
# of queries: 17148 |
21 |
Correct |
204 ms |
344 KB |
# of queries: 16194 |
22 |
Correct |
224 ms |
344 KB |
# of queries: 18259 |
23 |
Correct |
235 ms |
344 KB |
# of queries: 18188 |
24 |
Correct |
76 ms |
344 KB |
# of queries: 8235 |
25 |
Correct |
225 ms |
344 KB |
# of queries: 17736 |
26 |
Correct |
191 ms |
344 KB |
# of queries: 16233 |
27 |
Correct |
86 ms |
344 KB |
# of queries: 8526 |
28 |
Correct |
178 ms |
344 KB |
# of queries: 15940 |
29 |
Correct |
197 ms |
344 KB |
# of queries: 15922 |
30 |
Correct |
194 ms |
344 KB |
# of queries: 15940 |