#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;
// srand(time(0));
for (int l = 1, r = n / uniq; l <= r; ) {
int mid = (1 + l + r) >> 1;
in.clear();
std::vector <int> new_pool;
// std::random_shuffle(pool.begin(), pool.end());
for (int i : pool) {
inside(i);
in.push_back(i);
if ((int) IN.size() == uniq * mid + 1 || 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 |
0 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 |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
6 ms |
876 KB |
Output is correct |
9 |
Correct |
8 ms |
1368 KB |
Output is correct |
10 |
Correct |
4 ms |
708 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
856 KB |
Output is correct |
13 |
Correct |
6 ms |
1196 KB |
Output is correct |
14 |
Correct |
6 ms |
600 KB |
Output is correct |
15 |
Correct |
6 ms |
600 KB |
Output is correct |
16 |
Correct |
7 ms |
760 KB |
Output is correct |
17 |
Correct |
6 ms |
856 KB |
Output is correct |
18 |
Correct |
6 ms |
908 KB |
Output is correct |
19 |
Correct |
7 ms |
856 KB |
Output is correct |
20 |
Correct |
6 ms |
852 KB |
Output is correct |
21 |
Correct |
4 ms |
856 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
6 ms |
876 KB |
Output is correct |
9 |
Correct |
8 ms |
1368 KB |
Output is correct |
10 |
Correct |
4 ms |
708 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
856 KB |
Output is correct |
13 |
Correct |
6 ms |
1196 KB |
Output is correct |
14 |
Correct |
6 ms |
600 KB |
Output is correct |
15 |
Correct |
6 ms |
600 KB |
Output is correct |
16 |
Correct |
7 ms |
760 KB |
Output is correct |
17 |
Correct |
6 ms |
856 KB |
Output is correct |
18 |
Correct |
6 ms |
908 KB |
Output is correct |
19 |
Correct |
7 ms |
856 KB |
Output is correct |
20 |
Correct |
6 ms |
852 KB |
Output is correct |
21 |
Correct |
4 ms |
856 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
100 ms |
2768 KB |
Output is correct |
24 |
Correct |
92 ms |
2992 KB |
Output is correct |
25 |
Correct |
173 ms |
4128 KB |
Output is correct |
26 |
Correct |
189 ms |
4824 KB |
Output is correct |
27 |
Correct |
66 ms |
2376 KB |
Output is correct |
28 |
Correct |
62 ms |
2072 KB |
Output is correct |
29 |
Correct |
97 ms |
2720 KB |
Output is correct |
30 |
Correct |
131 ms |
3808 KB |
Output is correct |
31 |
Correct |
161 ms |
3864 KB |
Output is correct |
32 |
Correct |
168 ms |
4192 KB |
Output is correct |
33 |
Correct |
198 ms |
5020 KB |
Output is correct |
34 |
Correct |
180 ms |
4252 KB |
Output is correct |
35 |
Correct |
161 ms |
3996 KB |
Output is correct |
36 |
Correct |
175 ms |
4592 KB |
Output is correct |
37 |
Correct |
184 ms |
4716 KB |
Output is correct |
38 |
Correct |
130 ms |
3368 KB |
Output is correct |
39 |
Correct |
137 ms |
3612 KB |
Output is correct |
40 |
Correct |
132 ms |
3348 KB |
Output is correct |
41 |
Correct |
74 ms |
2064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
466 ms |
9072 KB |
Output is correct |
8 |
Correct |
420 ms |
9404 KB |
Output is correct |
9 |
Correct |
721 ms |
13480 KB |
Output is correct |
10 |
Correct |
920 ms |
16852 KB |
Output is correct |
11 |
Correct |
303 ms |
5612 KB |
Output is correct |
12 |
Correct |
558 ms |
9136 KB |
Output is correct |
13 |
Correct |
475 ms |
7380 KB |
Output is correct |
14 |
Correct |
573 ms |
9360 KB |
Output is correct |
15 |
Correct |
639 ms |
12244 KB |
Output is correct |
16 |
Correct |
664 ms |
12668 KB |
Output is correct |
17 |
Correct |
695 ms |
13080 KB |
Output is correct |
18 |
Correct |
765 ms |
14560 KB |
Output is correct |
19 |
Correct |
760 ms |
14064 KB |
Output is correct |
20 |
Correct |
828 ms |
14884 KB |
Output is correct |
21 |
Correct |
891 ms |
15696 KB |
Output is correct |
22 |
Correct |
727 ms |
11892 KB |
Output is correct |
23 |
Correct |
620 ms |
9888 KB |
Output is correct |
24 |
Correct |
749 ms |
12900 KB |
Output is correct |
25 |
Correct |
634 ms |
11352 KB |
Output is correct |
26 |
Correct |
363 ms |
6900 KB |
Output is correct |
27 |
Correct |
983 ms |
18652 KB |
Output is correct |
28 |
Correct |
484 ms |
9692 KB |
Output is correct |
29 |
Correct |
984 ms |
18736 KB |
Output is correct |
30 |
Correct |
987 ms |
18668 KB |
Output is correct |
31 |
Partially correct |
989 ms |
15096 KB |
Output is partially correct |
32 |
Correct |
965 ms |
17096 KB |
Output is correct |
33 |
Correct |
627 ms |
9656 KB |
Output is correct |
34 |
Correct |
594 ms |
9864 KB |
Output is correct |
35 |
Correct |
994 ms |
18152 KB |
Output is correct |
36 |
Correct |
808 ms |
14060 KB |
Output is correct |
37 |
Partially correct |
1040 ms |
14908 KB |
Output is partially correct |
38 |
Partially correct |
986 ms |
14880 KB |
Output is partially correct |
39 |
Correct |
1014 ms |
18044 KB |
Output is correct |
40 |
Correct |
532 ms |
8860 KB |
Output is correct |
41 |
Correct |
809 ms |
14016 KB |
Output is correct |
42 |
Correct |
1033 ms |
18560 KB |
Output is correct |
43 |
Correct |
25 ms |
1476 KB |
Output is correct |
44 |
Correct |
239 ms |
3464 KB |
Output is correct |
45 |
Correct |
489 ms |
9184 KB |
Output is correct |
46 |
Correct |
327 ms |
6700 KB |
Output is correct |
47 |
Correct |
589 ms |
10776 KB |
Output is correct |
48 |
Correct |
436 ms |
8660 KB |
Output is correct |