#include<bits/stdc++.h>
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
const int N = 1e5 + 10;
bool taken[N];
int n;
int query(vector<int> v) {
vector<int> ask(n);
for(int &j : v) ask[j - 1] = 1;
return Query(ask);
}
vector<int> operator + (vector<int> a, vector<int> b) {
vector<int> c = a;
for(int &j : b) c.push_back(j);
return c;
}
int Find(vector<int> lst, int x, int y) {
if (lst.size() == 1) return lst[0];
vector<int> Left, Right;
for(int i = 0; i < lst.size(); i++) {
if (i < lst.size() / 2) Left.push_back(lst[i]);
else Right.push_back(lst[i]);
}
vector<int> v1 = {x, y}, v2 = {y};
if (query(Left + v1) + 1 == query(Left + v2)) return Find(Left, x, y);
return Find(Right, x, y);
}
void Solve(int N)
{
n = N;
if (n == 1) {
Answer({1});
return;
}
if (n == 2) {
Answer({1, 2});
return;
}
int l = 1, r = n;
for(int i = 1; i <= n; i++) if (i != l && query({l, i}) == 1) {
r = i;
break;
}
taken[l] = taken[r] = 1;
vector<int> init;
for(int i = 1; i <= n; i++) if (!taken[i]) init.push_back(i);
int tmp = Find(init, l, r);
if (query({tmp, l, r}) != 1) {
swap(l, r);
tmp = Find(init, l, r);
// cout << "NGU";
}
else if (query({tmp, r}) == 1) swap(l, r);
taken[tmp] = 1;
int x, y;
vector<int> f, g, h = {tmp, l, r};
x = tmp; y = l;
// cout << tmp << " " << l << " " << r << endl;
while (1) {
vector<int> ask;
for(int i = 1; i <= n; i++) if (!taken[i]) ask.push_back(i);
if (ask.empty()) break;
int idx = Find(ask, x, y);
if (query({idx, x, y}) != 1) break;
y = x; x = idx;
taken[idx] = 1;
f.push_back(idx);
}
x = r; y = l;
while (1) {
vector<int> ask;
for(int i = 1; i <= n; i++) if (!taken[i]) ask.push_back(i);
if (ask.empty()) break;
int idx = Find(ask, x, y);
if (query({idx, x, y}) != 1) break;
y = x; x = idx;
taken[idx] = 1;
g.push_back(idx);
}
reverse(f.begin(), f.end());
Answer(f + h + g);
}
Compilation message
library.cpp: In function 'int Find(std::vector<int>, int, int)':
library.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i = 0; i < lst.size(); i++) {
| ~~^~~~~~~~~~~~
library.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if (i < lst.size() / 2) Left.push_back(lst[i]);
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
308 KB |
# of queries: 2657 |
2 |
Correct |
43 ms |
348 KB |
# of queries: 2723 |
3 |
Correct |
35 ms |
340 KB |
# of queries: 2778 |
4 |
Correct |
42 ms |
328 KB |
# of queries: 2765 |
5 |
Correct |
34 ms |
328 KB |
# of queries: 2891 |
6 |
Correct |
35 ms |
348 KB |
# of queries: 2737 |
7 |
Correct |
40 ms |
340 KB |
# of queries: 2706 |
8 |
Correct |
28 ms |
304 KB |
# of queries: 2690 |
9 |
Correct |
40 ms |
320 KB |
# of queries: 2746 |
10 |
Correct |
26 ms |
316 KB |
# of queries: 1575 |
11 |
Correct |
1 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
228 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
208 KB |
# of queries: 3 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 8 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 99 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 225 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
308 KB |
# of queries: 2657 |
2 |
Correct |
43 ms |
348 KB |
# of queries: 2723 |
3 |
Correct |
35 ms |
340 KB |
# of queries: 2778 |
4 |
Correct |
42 ms |
328 KB |
# of queries: 2765 |
5 |
Correct |
34 ms |
328 KB |
# of queries: 2891 |
6 |
Correct |
35 ms |
348 KB |
# of queries: 2737 |
7 |
Correct |
40 ms |
340 KB |
# of queries: 2706 |
8 |
Correct |
28 ms |
304 KB |
# of queries: 2690 |
9 |
Correct |
40 ms |
320 KB |
# of queries: 2746 |
10 |
Correct |
26 ms |
316 KB |
# of queries: 1575 |
11 |
Correct |
1 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
228 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
208 KB |
# of queries: 3 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 8 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 99 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 225 |
17 |
Correct |
288 ms |
424 KB |
# of queries: 18404 |
18 |
Correct |
370 ms |
456 KB |
# of queries: 18551 |
19 |
Correct |
360 ms |
428 KB |
# of queries: 18420 |
20 |
Correct |
324 ms |
540 KB |
# of queries: 17567 |
21 |
Correct |
269 ms |
472 KB |
# of queries: 16365 |
22 |
Correct |
331 ms |
604 KB |
# of queries: 18519 |
23 |
Correct |
348 ms |
476 KB |
# of queries: 18492 |
24 |
Correct |
129 ms |
348 KB |
# of queries: 8625 |
25 |
Correct |
282 ms |
500 KB |
# of queries: 18557 |
26 |
Correct |
320 ms |
468 KB |
# of queries: 16998 |
27 |
Correct |
134 ms |
504 KB |
# of queries: 8324 |
28 |
Correct |
295 ms |
420 KB |
# of queries: 16957 |
29 |
Correct |
272 ms |
416 KB |
# of queries: 16938 |
30 |
Correct |
258 ms |
656 KB |
# of queries: 16957 |