#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 = 2, 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 (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 |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
388 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
844 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
7 ms |
1112 KB |
Output is correct |
9 |
Correct |
6 ms |
904 KB |
Output is correct |
10 |
Correct |
6 ms |
1728 KB |
Output is correct |
11 |
Correct |
3 ms |
600 KB |
Output is correct |
12 |
Correct |
6 ms |
1112 KB |
Output is correct |
13 |
Correct |
6 ms |
600 KB |
Output is correct |
14 |
Correct |
7 ms |
856 KB |
Output is correct |
15 |
Correct |
7 ms |
856 KB |
Output is correct |
16 |
Correct |
7 ms |
768 KB |
Output is correct |
17 |
Correct |
7 ms |
600 KB |
Output is correct |
18 |
Correct |
7 ms |
856 KB |
Output is correct |
19 |
Correct |
6 ms |
976 KB |
Output is correct |
20 |
Correct |
7 ms |
864 KB |
Output is correct |
21 |
Correct |
5 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 |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
388 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
844 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
7 ms |
1112 KB |
Output is correct |
9 |
Correct |
6 ms |
904 KB |
Output is correct |
10 |
Correct |
6 ms |
1728 KB |
Output is correct |
11 |
Correct |
3 ms |
600 KB |
Output is correct |
12 |
Correct |
6 ms |
1112 KB |
Output is correct |
13 |
Correct |
6 ms |
600 KB |
Output is correct |
14 |
Correct |
7 ms |
856 KB |
Output is correct |
15 |
Correct |
7 ms |
856 KB |
Output is correct |
16 |
Correct |
7 ms |
768 KB |
Output is correct |
17 |
Correct |
7 ms |
600 KB |
Output is correct |
18 |
Correct |
7 ms |
856 KB |
Output is correct |
19 |
Correct |
6 ms |
976 KB |
Output is correct |
20 |
Correct |
7 ms |
864 KB |
Output is correct |
21 |
Correct |
5 ms |
856 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
244 ms |
5404 KB |
Output is correct |
24 |
Correct |
89 ms |
2648 KB |
Output is correct |
25 |
Correct |
248 ms |
5300 KB |
Output is correct |
26 |
Correct |
227 ms |
4928 KB |
Output is correct |
27 |
Correct |
74 ms |
2448 KB |
Output is correct |
28 |
Correct |
56 ms |
1824 KB |
Output is correct |
29 |
Correct |
120 ms |
3088 KB |
Output is correct |
30 |
Correct |
173 ms |
3316 KB |
Output is correct |
31 |
Correct |
246 ms |
5256 KB |
Output is correct |
32 |
Correct |
255 ms |
5300 KB |
Output is correct |
33 |
Correct |
252 ms |
5564 KB |
Output is correct |
34 |
Correct |
246 ms |
5316 KB |
Output is correct |
35 |
Correct |
247 ms |
5840 KB |
Output is correct |
36 |
Correct |
241 ms |
5184 KB |
Output is correct |
37 |
Correct |
248 ms |
5080 KB |
Output is correct |
38 |
Correct |
174 ms |
3928 KB |
Output is correct |
39 |
Correct |
210 ms |
5080 KB |
Output is correct |
40 |
Correct |
132 ms |
3424 KB |
Output is correct |
41 |
Correct |
76 ms |
1888 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 |
1075 ms |
19724 KB |
Output is correct |
8 |
Correct |
412 ms |
8676 KB |
Output is correct |
9 |
Correct |
1055 ms |
18268 KB |
Output is correct |
10 |
Correct |
838 ms |
12100 KB |
Output is correct |
11 |
Correct |
390 ms |
5588 KB |
Output is correct |
12 |
Correct |
546 ms |
9104 KB |
Output is correct |
13 |
Correct |
560 ms |
7516 KB |
Output is correct |
14 |
Correct |
735 ms |
10492 KB |
Output is correct |
15 |
Correct |
1056 ms |
19116 KB |
Output is correct |
16 |
Correct |
1093 ms |
19612 KB |
Output is correct |
17 |
Correct |
1069 ms |
19000 KB |
Output is correct |
18 |
Correct |
1067 ms |
18724 KB |
Output is correct |
19 |
Correct |
1074 ms |
18660 KB |
Output is correct |
20 |
Correct |
1077 ms |
18628 KB |
Output is correct |
21 |
Correct |
1096 ms |
17472 KB |
Output is correct |
22 |
Correct |
856 ms |
12172 KB |
Output is correct |
23 |
Correct |
863 ms |
12756 KB |
Output is correct |
24 |
Correct |
795 ms |
13256 KB |
Output is correct |
25 |
Correct |
644 ms |
10944 KB |
Output is correct |
26 |
Correct |
356 ms |
6780 KB |
Output is correct |
27 |
Correct |
1062 ms |
18556 KB |
Output is correct |
28 |
Correct |
1065 ms |
18492 KB |
Output is correct |
29 |
Correct |
1048 ms |
18856 KB |
Output is correct |
30 |
Correct |
1056 ms |
19068 KB |
Output is correct |
31 |
Correct |
851 ms |
12484 KB |
Output is correct |
32 |
Correct |
841 ms |
12496 KB |
Output is correct |
33 |
Partially correct |
823 ms |
11708 KB |
Output is partially correct |
34 |
Partially correct |
854 ms |
11816 KB |
Output is partially correct |
35 |
Correct |
1066 ms |
18640 KB |
Output is correct |
36 |
Correct |
1051 ms |
19188 KB |
Output is correct |
37 |
Correct |
995 ms |
16992 KB |
Output is correct |
38 |
Correct |
1000 ms |
17528 KB |
Output is correct |
39 |
Correct |
1041 ms |
18196 KB |
Output is correct |
40 |
Correct |
1072 ms |
18428 KB |
Output is correct |
41 |
Correct |
1075 ms |
18824 KB |
Output is correct |
42 |
Correct |
1081 ms |
18696 KB |
Output is correct |
43 |
Correct |
31 ms |
1652 KB |
Output is correct |
44 |
Correct |
272 ms |
3164 KB |
Output is correct |
45 |
Correct |
1129 ms |
19628 KB |
Output is correct |
46 |
Correct |
322 ms |
7104 KB |
Output is correct |
47 |
Correct |
593 ms |
10940 KB |
Output is correct |
48 |
Correct |
440 ms |
8900 KB |
Output is correct |