#include "library.h"
/// 123
#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
using namespace std;
void Solve(int N) {
if (N == 1) return void(Answer({1}));
vector<int> ask(N, 1);
int start = -1;
for (int i = 0; i < N; i++) {
ask[i] = 0;
if (Query(ask) == 1) {
start = i;
}
ask[i] = 1;
}
assert(start != -1);
vector<int> res(1, start + 1);
vector<int> rem(N);
iota(rem.begin(), rem.end(), 1);
while (true) {
for (int i = 0; i < rem.size(); i++) {
if (rem[i] == res.back()) {
swap(rem[i], rem.back());
rem.pop_back();
break;
}
}
if (rem.size() == 1) {
res.emplace_back(rem[0]);
return void(Answer(res));
}
int l = 1, r = rem.size(), nxt = -1;
while (l <= r) {
int mid = l + r >> 1;
ask = vector<int>(N, 0);
for (int i = 0; i < mid; i++) ask[rem[i] - 1] = 1;
for (int i : res) ask[i - 1] = 1;
int x = Query(ask);
for (int i : res) ask[i - 1] = 0;
int y = count(ask.begin(), ask.end(), 1) ? Query(ask) : 0;
if (x == y) {
nxt = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
res.emplace_back(rem[nxt - 1]);
}
}
Compilation message
library.cpp: In function 'void Solve(int)':
library.cpp:25:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < rem.size(); i++) {
| ~~^~~~~~~~~~~~
library.cpp:38:37: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
296 KB |
# of queries: 2578 |
2 |
Correct |
26 ms |
208 KB |
# of queries: 2567 |
3 |
Correct |
17 ms |
296 KB |
# of queries: 2708 |
4 |
Correct |
17 ms |
304 KB |
# of queries: 2708 |
5 |
Correct |
24 ms |
304 KB |
# of queries: 2722 |
6 |
Correct |
26 ms |
208 KB |
# of queries: 2710 |
7 |
Correct |
32 ms |
208 KB |
# of queries: 2718 |
8 |
Correct |
33 ms |
296 KB |
# of queries: 2573 |
9 |
Correct |
26 ms |
208 KB |
# of queries: 2687 |
10 |
Correct |
12 ms |
296 KB |
# of queries: 1585 |
11 |
Correct |
1 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 2 |
13 |
Correct |
0 ms |
208 KB |
# of queries: 5 |
14 |
Correct |
0 ms |
208 KB |
# of queries: 12 |
15 |
Correct |
1 ms |
208 KB |
# of queries: 93 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 211 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
296 KB |
# of queries: 2578 |
2 |
Correct |
26 ms |
208 KB |
# of queries: 2567 |
3 |
Correct |
17 ms |
296 KB |
# of queries: 2708 |
4 |
Correct |
17 ms |
304 KB |
# of queries: 2708 |
5 |
Correct |
24 ms |
304 KB |
# of queries: 2722 |
6 |
Correct |
26 ms |
208 KB |
# of queries: 2710 |
7 |
Correct |
32 ms |
208 KB |
# of queries: 2718 |
8 |
Correct |
33 ms |
296 KB |
# of queries: 2573 |
9 |
Correct |
26 ms |
208 KB |
# of queries: 2687 |
10 |
Correct |
12 ms |
296 KB |
# of queries: 1585 |
11 |
Correct |
1 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 2 |
13 |
Correct |
0 ms |
208 KB |
# of queries: 5 |
14 |
Correct |
0 ms |
208 KB |
# of queries: 12 |
15 |
Correct |
1 ms |
208 KB |
# of queries: 93 |
16 |
Correct |
3 ms |
208 KB |
# of queries: 211 |
17 |
Correct |
222 ms |
296 KB |
# of queries: 18210 |
18 |
Correct |
235 ms |
304 KB |
# of queries: 17925 |
19 |
Correct |
243 ms |
304 KB |
# of queries: 18182 |
20 |
Correct |
235 ms |
292 KB |
# of queries: 16920 |
21 |
Correct |
213 ms |
292 KB |
# of queries: 15939 |
22 |
Correct |
212 ms |
296 KB |
# of queries: 18194 |
23 |
Correct |
255 ms |
300 KB |
# of queries: 18153 |
24 |
Correct |
106 ms |
292 KB |
# of queries: 8313 |
25 |
Correct |
240 ms |
320 KB |
# of queries: 17749 |
26 |
Correct |
156 ms |
304 KB |
# of queries: 16603 |
27 |
Correct |
94 ms |
304 KB |
# of queries: 8293 |
28 |
Correct |
205 ms |
304 KB |
# of queries: 18952 |
29 |
Correct |
201 ms |
308 KB |
# of queries: 18931 |
30 |
Correct |
225 ms |
412 KB |
# of queries: 18952 |