#include "insects.h"
#include <set>
#include <iostream>
namespace ruhan {
using namespace std;
int N;
set<int> insects;
set<int> machine, new_added;
int last_pb = -1;
void work (int k) {
new_added.clear();
for (int i : insects) {
if (machine.count(i)) continue;
move_inside(i);
last_pb = press_button();
if (last_pb <= k) {
machine.insert(i);
new_added.insert(i);
} else {
move_outside(i);
}
}
}
void undo () {
for (int i : new_added) {
move_outside(i);
machine.erase(i);
}
new_added.clear();
}
int min_cardinality (int N_) {
N = N_;
machine.clear();
new_added.clear();
last_pb = -1;
insects.clear();
for (int i = 0; i < N; i++) {
insects.insert(i);
}
work(1);
const int T = machine.size();
if (T == 1) return N;
if (last_pb == 1) return 1;
int x = 1;
while (x <= N) x <<= 1;
x >>= 1;
int k = 1;
for (; x > 0; x >>= 1) {
if ((k + x) * T > N) continue;
work (k + x);
if ((int)machine.size() == (k + x) * T) {
k += x;
} else {
insects = machine;
undo();
}
}
return k;
}
};
int min_cardinality(int N) {
return ruhan::min_cardinality(N);
}
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
308 KB |
Output is correct |
9 |
Correct |
5 ms |
308 KB |
Output is correct |
10 |
Correct |
6 ms |
304 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
7 ms |
208 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
8 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
312 KB |
Output is correct |
19 |
Correct |
7 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
3 ms |
316 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
308 KB |
Output is correct |
9 |
Correct |
5 ms |
308 KB |
Output is correct |
10 |
Correct |
6 ms |
304 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
7 ms |
208 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
8 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
312 KB |
Output is correct |
19 |
Correct |
7 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
3 ms |
316 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
23 |
Correct |
8 ms |
336 KB |
Output is correct |
24 |
Correct |
10 ms |
344 KB |
Output is correct |
25 |
Correct |
23 ms |
340 KB |
Output is correct |
26 |
Correct |
28 ms |
340 KB |
Output is correct |
27 |
Correct |
20 ms |
336 KB |
Output is correct |
28 |
Correct |
15 ms |
368 KB |
Output is correct |
29 |
Correct |
26 ms |
336 KB |
Output is correct |
30 |
Correct |
31 ms |
344 KB |
Output is correct |
31 |
Correct |
24 ms |
336 KB |
Output is correct |
32 |
Correct |
31 ms |
344 KB |
Output is correct |
33 |
Correct |
38 ms |
356 KB |
Output is correct |
34 |
Correct |
26 ms |
392 KB |
Output is correct |
35 |
Correct |
27 ms |
348 KB |
Output is correct |
36 |
Correct |
26 ms |
340 KB |
Output is correct |
37 |
Correct |
37 ms |
388 KB |
Output is correct |
38 |
Correct |
35 ms |
336 KB |
Output is correct |
39 |
Correct |
26 ms |
360 KB |
Output is correct |
40 |
Correct |
18 ms |
364 KB |
Output is correct |
41 |
Correct |
10 ms |
400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
22 ms |
336 KB |
Output is correct |
8 |
Correct |
11 ms |
548 KB |
Output is correct |
9 |
Correct |
46 ms |
384 KB |
Output is correct |
10 |
Partially correct |
58 ms |
504 KB |
Output is partially correct |
11 |
Correct |
56 ms |
336 KB |
Output is correct |
12 |
Correct |
14 ms |
496 KB |
Output is correct |
13 |
Partially correct |
48 ms |
388 KB |
Output is partially correct |
14 |
Partially correct |
53 ms |
456 KB |
Output is partially correct |
15 |
Correct |
61 ms |
452 KB |
Output is correct |
16 |
Correct |
50 ms |
456 KB |
Output is correct |
17 |
Correct |
62 ms |
632 KB |
Output is correct |
18 |
Correct |
40 ms |
516 KB |
Output is correct |
19 |
Partially correct |
63 ms |
504 KB |
Output is partially correct |
20 |
Correct |
63 ms |
460 KB |
Output is correct |
21 |
Partially correct |
56 ms |
512 KB |
Output is partially correct |
22 |
Partially correct |
42 ms |
640 KB |
Output is partially correct |
23 |
Partially correct |
71 ms |
456 KB |
Output is partially correct |
24 |
Correct |
37 ms |
468 KB |
Output is correct |
25 |
Correct |
29 ms |
416 KB |
Output is correct |
26 |
Correct |
22 ms |
488 KB |
Output is correct |
27 |
Correct |
58 ms |
428 KB |
Output is correct |
28 |
Correct |
61 ms |
396 KB |
Output is correct |
29 |
Partially correct |
68 ms |
504 KB |
Output is partially correct |
30 |
Partially correct |
62 ms |
484 KB |
Output is partially correct |
31 |
Partially correct |
79 ms |
508 KB |
Output is partially correct |
32 |
Partially correct |
63 ms |
520 KB |
Output is partially correct |
33 |
Partially correct |
73 ms |
548 KB |
Output is partially correct |
34 |
Partially correct |
62 ms |
644 KB |
Output is partially correct |
35 |
Partially correct |
68 ms |
616 KB |
Output is partially correct |
36 |
Partially correct |
63 ms |
500 KB |
Output is partially correct |
37 |
Partially correct |
77 ms |
528 KB |
Output is partially correct |
38 |
Partially correct |
72 ms |
508 KB |
Output is partially correct |
39 |
Correct |
69 ms |
424 KB |
Output is correct |
40 |
Correct |
79 ms |
380 KB |
Output is correct |
41 |
Correct |
40 ms |
584 KB |
Output is correct |
42 |
Correct |
32 ms |
524 KB |
Output is correct |
43 |
Correct |
13 ms |
320 KB |
Output is correct |
44 |
Correct |
56 ms |
376 KB |
Output is correct |
45 |
Correct |
52 ms |
368 KB |
Output is correct |
46 |
Correct |
29 ms |
464 KB |
Output is correct |
47 |
Correct |
39 ms |
464 KB |
Output is correct |
48 |
Correct |
39 ms |
576 KB |
Output is correct |