#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
set<int> s;
set<int> invalid;
void add(int i) {
assert(!s.count(i));
s.insert(i);
move_inside(i);
}
void del(int i) {
assert(s.count(i));
s.erase(i);
move_outside(i);
}
int get() {
return press_button();
}
int get_s_cardinality() {
int sol = 0;
for (auto &x : s) {
if (!invalid.count(x)) {
sol++;
}
}
return sol;
}
int min_cardinality(int n) {
int cnt_distinct = 0;
for (int i = 0; i < n; i++) {
add(i);
if (get() == 1) {
cnt_distinct++;
} else {
del(i);
}
}
for (auto &i : s) {
invalid.insert(i);
}
int low = 1, high = n, sol = 1;
while (low <= high) {
assert(low >= 1);
{
int cnt_valid = 0;
for (int i = 0; i < n; i++) {
if (invalid.count(i)) continue;
cnt_valid++;
}
high = min(high, cnt_valid / cnt_distinct);
}
if (!(low <= high)) break;
int mid = (low + high) / 2;
vector<int> added_now, wait_now;
for (int i = 0; i < n; i++) {
if (invalid.count(i)) continue;
add(i);
if (get() > mid + sol) {
del(i);
wait_now.push_back(i);
} else {
added_now.push_back(i);
}
}
if (get_s_cardinality() == mid * cnt_distinct) {
for (auto &i : added_now) {
invalid.insert(i);
}
int delta = mid;
low = mid + 1;
sol += delta;
low -= delta;
high -= delta;
} else {
for (auto &i : added_now) {
del(i);
}
for (auto &i : wait_now) {
invalid.insert(i);
}
high = mid - 1;
}
}
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
4 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
300 KB |
Output is correct |
9 |
Correct |
5 ms |
304 KB |
Output is correct |
10 |
Correct |
5 ms |
300 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
7 ms |
304 KB |
Output is correct |
13 |
Correct |
7 ms |
308 KB |
Output is correct |
14 |
Correct |
7 ms |
304 KB |
Output is correct |
15 |
Correct |
3 ms |
300 KB |
Output is correct |
16 |
Correct |
5 ms |
300 KB |
Output is correct |
17 |
Correct |
4 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
300 KB |
Output is correct |
19 |
Correct |
6 ms |
300 KB |
Output is correct |
20 |
Correct |
5 ms |
308 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
4 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
300 KB |
Output is correct |
9 |
Correct |
5 ms |
304 KB |
Output is correct |
10 |
Correct |
5 ms |
300 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
7 ms |
304 KB |
Output is correct |
13 |
Correct |
7 ms |
308 KB |
Output is correct |
14 |
Correct |
7 ms |
304 KB |
Output is correct |
15 |
Correct |
3 ms |
300 KB |
Output is correct |
16 |
Correct |
5 ms |
300 KB |
Output is correct |
17 |
Correct |
4 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
300 KB |
Output is correct |
19 |
Correct |
6 ms |
300 KB |
Output is correct |
20 |
Correct |
5 ms |
308 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
23 |
Correct |
40 ms |
368 KB |
Output is correct |
24 |
Correct |
8 ms |
336 KB |
Output is correct |
25 |
Correct |
31 ms |
336 KB |
Output is correct |
26 |
Correct |
33 ms |
276 KB |
Output is correct |
27 |
Correct |
17 ms |
324 KB |
Output is correct |
28 |
Correct |
8 ms |
312 KB |
Output is correct |
29 |
Correct |
30 ms |
428 KB |
Output is correct |
30 |
Correct |
24 ms |
304 KB |
Output is correct |
31 |
Correct |
28 ms |
336 KB |
Output is correct |
32 |
Correct |
25 ms |
288 KB |
Output is correct |
33 |
Correct |
34 ms |
296 KB |
Output is correct |
34 |
Correct |
24 ms |
292 KB |
Output is correct |
35 |
Correct |
16 ms |
320 KB |
Output is correct |
36 |
Correct |
31 ms |
336 KB |
Output is correct |
37 |
Correct |
29 ms |
300 KB |
Output is correct |
38 |
Correct |
19 ms |
316 KB |
Output is correct |
39 |
Correct |
25 ms |
308 KB |
Output is correct |
40 |
Correct |
12 ms |
340 KB |
Output is correct |
41 |
Correct |
8 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
288 KB |
Output is correct |
7 |
Correct |
57 ms |
392 KB |
Output is correct |
8 |
Correct |
18 ms |
456 KB |
Output is correct |
9 |
Correct |
62 ms |
432 KB |
Output is correct |
10 |
Correct |
44 ms |
484 KB |
Output is correct |
11 |
Correct |
51 ms |
296 KB |
Output is correct |
12 |
Correct |
23 ms |
316 KB |
Output is correct |
13 |
Correct |
46 ms |
412 KB |
Output is correct |
14 |
Correct |
59 ms |
368 KB |
Output is correct |
15 |
Correct |
64 ms |
408 KB |
Output is correct |
16 |
Correct |
54 ms |
400 KB |
Output is correct |
17 |
Correct |
56 ms |
536 KB |
Output is correct |
18 |
Correct |
61 ms |
408 KB |
Output is correct |
19 |
Partially correct |
63 ms |
432 KB |
Output is partially correct |
20 |
Correct |
51 ms |
420 KB |
Output is correct |
21 |
Correct |
54 ms |
380 KB |
Output is correct |
22 |
Correct |
53 ms |
360 KB |
Output is correct |
23 |
Correct |
42 ms |
328 KB |
Output is correct |
24 |
Correct |
47 ms |
300 KB |
Output is correct |
25 |
Correct |
17 ms |
400 KB |
Output is correct |
26 |
Correct |
22 ms |
320 KB |
Output is correct |
27 |
Correct |
64 ms |
404 KB |
Output is correct |
28 |
Correct |
27 ms |
552 KB |
Output is correct |
29 |
Partially correct |
57 ms |
540 KB |
Output is partially correct |
30 |
Partially correct |
59 ms |
404 KB |
Output is partially correct |
31 |
Correct |
61 ms |
400 KB |
Output is correct |
32 |
Correct |
58 ms |
448 KB |
Output is correct |
33 |
Correct |
55 ms |
336 KB |
Output is correct |
34 |
Correct |
48 ms |
296 KB |
Output is correct |
35 |
Partially correct |
63 ms |
424 KB |
Output is partially correct |
36 |
Partially correct |
33 ms |
456 KB |
Output is partially correct |
37 |
Correct |
48 ms |
404 KB |
Output is correct |
38 |
Correct |
49 ms |
408 KB |
Output is correct |
39 |
Correct |
65 ms |
440 KB |
Output is correct |
40 |
Correct |
60 ms |
420 KB |
Output is correct |
41 |
Partially correct |
29 ms |
464 KB |
Output is partially correct |
42 |
Partially correct |
45 ms |
464 KB |
Output is partially correct |
43 |
Correct |
7 ms |
300 KB |
Output is correct |
44 |
Correct |
40 ms |
292 KB |
Output is correct |
45 |
Correct |
54 ms |
424 KB |
Output is correct |
46 |
Correct |
24 ms |
312 KB |
Output is correct |
47 |
Correct |
31 ms |
328 KB |
Output is correct |
48 |
Correct |
22 ms |
384 KB |
Output is correct |