#include "insects.h"
#include <bits/stdc++.h>
std::set <int> IN;
std::set <int> last;
void inside(int x) {
IN.insert(x);
}
void outside(int x) {
IN.erase(x);
}
int ask(int n) {
for (int i = 0; i < n; i++) {
if (IN.count(i) && !last.count(i)) {
move_inside(i);
} else if (!IN.count(i) && last.count(i)) {
move_outside(i);
}
}
static std::map <std::vector <int>, int> mem;
last = IN;
std::vector <int> tmp;
for (int x : IN) tmp.push_back(x);
auto it = mem.find(tmp);
if (it != mem.end()) return it->second;
return mem[tmp] = press_button();
// return press_button();
}
std::vector <int> invert(std::vector <int> v, int n) {
std::vector <int> u;
std::sort(v.begin(), v.end());
for (int i = 0, j = 0; i < n; i++) {
if (j < (int) v.size() && v[j] == i) {
j++;
continue;
}
u.push_back(i);
}
return u;
}
int min_cardinality(int n) {
std::vector <int> in, pool;
for (int i = 0; i < n; i++) {
inside(i);
in.push_back(i);
if (ask(n) == 1) continue;
outside(i);
in.pop_back();
pool.push_back(i);
}
int uniq = in.size();
int ans = 1;
for (int l = 2, r = n / uniq; l <= r; ) {
int mid = (1 + l + r) >> 1;
in.clear();
std::vector <int> new_pool;
for (int i : pool) {
inside(i);
in.push_back(i);
if (ask(n) > mid) {
outside(i);
in.pop_back();
new_pool.push_back(i);
continue;
}
}
pool = new_pool;
if ((int) IN.size() == uniq * mid) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
pool = in;
for (int x : in) {
outside(x);
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1112 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
9 ms |
1380 KB |
Output is correct |
9 |
Correct |
8 ms |
1112 KB |
Output is correct |
10 |
Correct |
4 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
856 KB |
Output is correct |
13 |
Correct |
6 ms |
784 KB |
Output is correct |
14 |
Correct |
10 ms |
1804 KB |
Output is correct |
15 |
Correct |
6 ms |
856 KB |
Output is correct |
16 |
Correct |
7 ms |
1368 KB |
Output is correct |
17 |
Correct |
7 ms |
856 KB |
Output is correct |
18 |
Correct |
7 ms |
600 KB |
Output is correct |
19 |
Correct |
7 ms |
1192 KB |
Output is correct |
20 |
Correct |
7 ms |
1112 KB |
Output is correct |
21 |
Correct |
4 ms |
600 KB |
Output is correct |
22 |
Correct |
3 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1112 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
9 ms |
1380 KB |
Output is correct |
9 |
Correct |
8 ms |
1112 KB |
Output is correct |
10 |
Correct |
4 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
856 KB |
Output is correct |
13 |
Correct |
6 ms |
784 KB |
Output is correct |
14 |
Correct |
10 ms |
1804 KB |
Output is correct |
15 |
Correct |
6 ms |
856 KB |
Output is correct |
16 |
Correct |
7 ms |
1368 KB |
Output is correct |
17 |
Correct |
7 ms |
856 KB |
Output is correct |
18 |
Correct |
7 ms |
600 KB |
Output is correct |
19 |
Correct |
7 ms |
1192 KB |
Output is correct |
20 |
Correct |
7 ms |
1112 KB |
Output is correct |
21 |
Correct |
4 ms |
600 KB |
Output is correct |
22 |
Correct |
3 ms |
600 KB |
Output is correct |
23 |
Correct |
226 ms |
5404 KB |
Output is correct |
24 |
Correct |
88 ms |
2784 KB |
Output is correct |
25 |
Correct |
220 ms |
4980 KB |
Output is correct |
26 |
Correct |
208 ms |
4472 KB |
Output is correct |
27 |
Correct |
70 ms |
2644 KB |
Output is correct |
28 |
Correct |
57 ms |
2088 KB |
Output is correct |
29 |
Correct |
93 ms |
2504 KB |
Output is correct |
30 |
Correct |
131 ms |
3484 KB |
Output is correct |
31 |
Correct |
225 ms |
5500 KB |
Output is correct |
32 |
Correct |
231 ms |
5364 KB |
Output is correct |
33 |
Correct |
217 ms |
5568 KB |
Output is correct |
34 |
Correct |
232 ms |
5408 KB |
Output is correct |
35 |
Correct |
224 ms |
5496 KB |
Output is correct |
36 |
Correct |
220 ms |
4960 KB |
Output is correct |
37 |
Correct |
228 ms |
5840 KB |
Output is correct |
38 |
Correct |
166 ms |
3904 KB |
Output is correct |
39 |
Correct |
185 ms |
4664 KB |
Output is correct |
40 |
Correct |
141 ms |
3572 KB |
Output is correct |
41 |
Correct |
82 ms |
1808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1046 ms |
19316 KB |
Output is correct |
8 |
Correct |
411 ms |
8812 KB |
Output is correct |
9 |
Correct |
984 ms |
18348 KB |
Output is correct |
10 |
Correct |
714 ms |
11624 KB |
Output is correct |
11 |
Correct |
299 ms |
5132 KB |
Output is correct |
12 |
Correct |
556 ms |
9128 KB |
Output is correct |
13 |
Correct |
473 ms |
7628 KB |
Output is correct |
14 |
Correct |
620 ms |
10024 KB |
Output is correct |
15 |
Correct |
1034 ms |
19316 KB |
Output is correct |
16 |
Correct |
1020 ms |
19220 KB |
Output is correct |
17 |
Correct |
1008 ms |
18780 KB |
Output is correct |
18 |
Correct |
1008 ms |
18424 KB |
Output is correct |
19 |
Correct |
1046 ms |
18800 KB |
Output is correct |
20 |
Correct |
1046 ms |
18636 KB |
Output is correct |
21 |
Correct |
982 ms |
17344 KB |
Output is correct |
22 |
Correct |
763 ms |
12068 KB |
Output is correct |
23 |
Correct |
758 ms |
12704 KB |
Output is correct |
24 |
Correct |
756 ms |
13256 KB |
Output is correct |
25 |
Correct |
624 ms |
10756 KB |
Output is correct |
26 |
Correct |
370 ms |
6672 KB |
Output is correct |
27 |
Correct |
1004 ms |
18728 KB |
Output is correct |
28 |
Correct |
975 ms |
18696 KB |
Output is correct |
29 |
Correct |
1006 ms |
19144 KB |
Output is correct |
30 |
Correct |
1025 ms |
19032 KB |
Output is correct |
31 |
Correct |
725 ms |
11820 KB |
Output is correct |
32 |
Correct |
733 ms |
11964 KB |
Output is correct |
33 |
Partially correct |
687 ms |
10500 KB |
Output is partially correct |
34 |
Partially correct |
688 ms |
10344 KB |
Output is partially correct |
35 |
Correct |
959 ms |
18256 KB |
Output is correct |
36 |
Correct |
978 ms |
18440 KB |
Output is correct |
37 |
Correct |
906 ms |
14624 KB |
Output is correct |
38 |
Correct |
929 ms |
15208 KB |
Output is correct |
39 |
Correct |
973 ms |
18296 KB |
Output is correct |
40 |
Correct |
974 ms |
18324 KB |
Output is correct |
41 |
Correct |
1020 ms |
18428 KB |
Output is correct |
42 |
Correct |
980 ms |
18868 KB |
Output is correct |
43 |
Correct |
25 ms |
1792 KB |
Output is correct |
44 |
Correct |
237 ms |
3744 KB |
Output is correct |
45 |
Correct |
1010 ms |
19932 KB |
Output is correct |
46 |
Correct |
316 ms |
7076 KB |
Output is correct |
47 |
Correct |
589 ms |
10976 KB |
Output is correct |
48 |
Correct |
428 ms |
8968 KB |
Output is correct |