#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;
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);
taken[tmp] = 1;
if (query({tmp, r}) == 1) swap(l, r);
int x, y;
vector<int> f, g, h = {tmp, l, r};
x = tmp; 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;
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 |
31 ms |
344 KB |
# of queries: 2656 |
2 |
Correct |
21 ms |
304 KB |
# of queries: 2722 |
3 |
Correct |
37 ms |
332 KB |
# of queries: 2777 |
4 |
Correct |
30 ms |
336 KB |
# of queries: 2764 |
5 |
Correct |
48 ms |
324 KB |
# of queries: 2890 |
6 |
Correct |
45 ms |
340 KB |
# of queries: 2736 |
7 |
Correct |
33 ms |
336 KB |
# of queries: 2705 |
8 |
Correct |
29 ms |
332 KB |
# of queries: 2689 |
9 |
Correct |
34 ms |
320 KB |
# of queries: 2745 |
10 |
Correct |
22 ms |
208 KB |
# of queries: 1574 |
11 |
Runtime error |
184 ms |
5096 KB |
Execution killed with signal 13 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
344 KB |
# of queries: 2656 |
2 |
Correct |
21 ms |
304 KB |
# of queries: 2722 |
3 |
Correct |
37 ms |
332 KB |
# of queries: 2777 |
4 |
Correct |
30 ms |
336 KB |
# of queries: 2764 |
5 |
Correct |
48 ms |
324 KB |
# of queries: 2890 |
6 |
Correct |
45 ms |
340 KB |
# of queries: 2736 |
7 |
Correct |
33 ms |
336 KB |
# of queries: 2705 |
8 |
Correct |
29 ms |
332 KB |
# of queries: 2689 |
9 |
Correct |
34 ms |
320 KB |
# of queries: 2745 |
10 |
Correct |
22 ms |
208 KB |
# of queries: 1574 |
11 |
Runtime error |
184 ms |
5096 KB |
Execution killed with signal 13 |
12 |
Halted |
0 ms |
0 KB |
- |