#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
typedef long long ll;
int n;
vector<bool> in;
unordered_set<int> s;
int cnt;
int add(int i) {
if (in[i]) return 0;
move_inside(i);
cnt++;
in[i] = true;
return 1;
}
int remove(int i) {
if (!in[i]) return 0;
move_outside(i);
cnt--;
in[i] = false;
return 1;
}
int min_cardinality(int N) {
n = N;
cnt = 0;
mt19937 mt(time(0));
in = vector<bool>(n);
for (int i = 0; i < n; i++) {
add(i);
}
int mx = press_button();
int prevSz = cnt;
while (mx > 1) {
int cur = mx;
while (cur == mx) {
int i = mt()%n;
if (remove(i)) {
cur = press_button();
if (cur == mx) s.insert(i);
}
}
for (auto &e : s) {
if (add(e)) {
cur = press_button();
if (cur == mx) remove(e);
}
}
if (cnt * mx % (mx-1) == 0 && cnt * mx / (mx-1) == prevSz) {
break;
}
s.clear();
prevSz = cnt;
mx--;
}
return mx;
}
#ifdef TEST
#include "grader.cpp"
#endif
# |
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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
436 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
344 KB |
Output is correct |
18 |
Correct |
9 ms |
344 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
7 ms |
344 KB |
Output is correct |
21 |
Correct |
6 ms |
344 KB |
Output is correct |
22 |
Correct |
5 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
436 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
344 KB |
Output is correct |
18 |
Correct |
9 ms |
344 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
7 ms |
344 KB |
Output is correct |
21 |
Correct |
6 ms |
344 KB |
Output is correct |
22 |
Correct |
5 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
5 ms |
344 KB |
Output is correct |
26 |
Correct |
21 ms |
436 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
27 ms |
432 KB |
Output is correct |
29 |
Correct |
15 ms |
344 KB |
Output is correct |
30 |
Correct |
40 ms |
344 KB |
Output is correct |
31 |
Correct |
2 ms |
344 KB |
Output is correct |
32 |
Correct |
5 ms |
436 KB |
Output is correct |
33 |
Correct |
9 ms |
440 KB |
Output is correct |
34 |
Correct |
6 ms |
344 KB |
Output is correct |
35 |
Correct |
10 ms |
344 KB |
Output is correct |
36 |
Correct |
11 ms |
344 KB |
Output is correct |
37 |
Correct |
20 ms |
344 KB |
Output is correct |
38 |
Correct |
42 ms |
344 KB |
Output is correct |
39 |
Correct |
39 ms |
688 KB |
Output is correct |
40 |
Correct |
32 ms |
448 KB |
Output is correct |
41 |
Correct |
32 ms |
592 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 |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Partially correct |
59 ms |
440 KB |
Output is partially correct |
11 |
Correct |
14 ms |
344 KB |
Output is correct |
12 |
Partially correct |
54 ms |
412 KB |
Output is partially correct |
13 |
Partially correct |
33 ms |
344 KB |
Output is partially correct |
14 |
Partially correct |
98 ms |
424 KB |
Output is partially correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
440 KB |
Output is correct |
17 |
Correct |
8 ms |
344 KB |
Output is correct |
18 |
Correct |
8 ms |
344 KB |
Output is correct |
19 |
Correct |
14 ms |
344 KB |
Output is correct |
20 |
Correct |
12 ms |
344 KB |
Output is correct |
21 |
Partially correct |
62 ms |
344 KB |
Output is partially correct |
22 |
Partially correct |
56 ms |
432 KB |
Output is partially correct |
23 |
Partially correct |
88 ms |
580 KB |
Output is partially correct |
24 |
Partially correct |
100 ms |
492 KB |
Output is partially correct |
25 |
Partially correct |
86 ms |
476 KB |
Output is partially correct |
26 |
Partially correct |
71 ms |
480 KB |
Output is partially correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
6 ms |
444 KB |
Output is correct |
29 |
Correct |
6 ms |
440 KB |
Output is correct |
30 |
Correct |
5 ms |
344 KB |
Output is correct |
31 |
Partially correct |
50 ms |
344 KB |
Output is partially correct |
32 |
Partially correct |
50 ms |
344 KB |
Output is partially correct |
33 |
Partially correct |
99 ms |
452 KB |
Output is partially correct |
34 |
Partially correct |
93 ms |
704 KB |
Output is partially correct |
35 |
Correct |
6 ms |
692 KB |
Output is correct |
36 |
Correct |
12 ms |
436 KB |
Output is correct |
37 |
Partially correct |
39 ms |
448 KB |
Output is partially correct |
38 |
Partially correct |
45 ms |
344 KB |
Output is partially correct |
39 |
Correct |
8 ms |
440 KB |
Output is correct |
40 |
Correct |
11 ms |
448 KB |
Output is correct |
41 |
Correct |
6 ms |
344 KB |
Output is correct |
42 |
Correct |
6 ms |
452 KB |
Output is correct |
43 |
Correct |
6 ms |
344 KB |
Output is correct |
44 |
Correct |
23 ms |
344 KB |
Output is correct |
45 |
Correct |
1 ms |
344 KB |
Output is correct |
46 |
Partially correct |
105 ms |
668 KB |
Output is partially correct |
47 |
Partially correct |
88 ms |
672 KB |
Output is partially correct |
48 |
Partially correct |
103 ms |
416 KB |
Output is partially correct |