#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
int min_cardinality(int n){
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> sus(n); iota(sus.begin(), sus.end(), 0); shuffle(sus.begin(), sus.end(), rng);
set<int> s;
auto in=[&](int i){
if (s.count(i)) return;
s.insert(i);
move_inside(sus[i]);
};
auto out=[&](int i){
if (!s.count(i)) return;
s.erase(i);
move_outside(sus[i]);
};
for (int i=0; i<n; ++i){
in(i);
if (press_button()>1) out(i);
}
int cnt=s.size();
map<int, set<int>> memo;
memo[1]=s;
for (int i=0; i<n; ++i) memo[n].insert(i);
int l=2, r=n/cnt;
while (l<=r){
int mid=(l+r)>>1;
auto it=memo.lower_bound(mid);
set<int> t;
for (int i:it->second) if (!s.count(i)){
in(i);
if (press_button()>mid) out(i);
else t.insert(i);
if ((int)s.size()>=cnt*mid) break;
}
int k=s.size();
memo[mid]=s;
if (k>=cnt*mid) l=mid+1;
else{
r=mid-1;
for (int i:t) out(i);
}
}
return r;
}
# |
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 |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
6 ms |
300 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
7 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
320 KB |
Output is correct |
13 |
Correct |
6 ms |
300 KB |
Output is correct |
14 |
Correct |
7 ms |
300 KB |
Output is correct |
15 |
Correct |
5 ms |
336 KB |
Output is correct |
16 |
Correct |
6 ms |
336 KB |
Output is correct |
17 |
Correct |
8 ms |
304 KB |
Output is correct |
18 |
Correct |
6 ms |
320 KB |
Output is correct |
19 |
Correct |
5 ms |
336 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
4 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
300 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 |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
6 ms |
300 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
7 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
320 KB |
Output is correct |
13 |
Correct |
6 ms |
300 KB |
Output is correct |
14 |
Correct |
7 ms |
300 KB |
Output is correct |
15 |
Correct |
5 ms |
336 KB |
Output is correct |
16 |
Correct |
6 ms |
336 KB |
Output is correct |
17 |
Correct |
8 ms |
304 KB |
Output is correct |
18 |
Correct |
6 ms |
320 KB |
Output is correct |
19 |
Correct |
5 ms |
336 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
4 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
300 KB |
Output is correct |
23 |
Correct |
14 ms |
688 KB |
Output is correct |
24 |
Correct |
9 ms |
336 KB |
Output is correct |
25 |
Correct |
29 ms |
568 KB |
Output is correct |
26 |
Correct |
18 ms |
468 KB |
Output is correct |
27 |
Correct |
12 ms |
308 KB |
Output is correct |
28 |
Correct |
6 ms |
308 KB |
Output is correct |
29 |
Correct |
27 ms |
300 KB |
Output is correct |
30 |
Correct |
30 ms |
328 KB |
Output is correct |
31 |
Correct |
23 ms |
632 KB |
Output is correct |
32 |
Correct |
31 ms |
548 KB |
Output is correct |
33 |
Correct |
26 ms |
556 KB |
Output is correct |
34 |
Correct |
27 ms |
552 KB |
Output is correct |
35 |
Correct |
22 ms |
508 KB |
Output is correct |
36 |
Correct |
24 ms |
532 KB |
Output is correct |
37 |
Correct |
24 ms |
432 KB |
Output is correct |
38 |
Correct |
28 ms |
304 KB |
Output is correct |
39 |
Correct |
19 ms |
296 KB |
Output is correct |
40 |
Correct |
12 ms |
328 KB |
Output is correct |
41 |
Correct |
11 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
37 ms |
1316 KB |
Output is correct |
8 |
Correct |
25 ms |
480 KB |
Output is correct |
9 |
Correct |
38 ms |
932 KB |
Output is correct |
10 |
Correct |
57 ms |
668 KB |
Output is correct |
11 |
Correct |
54 ms |
420 KB |
Output is correct |
12 |
Correct |
38 ms |
464 KB |
Output is correct |
13 |
Correct |
47 ms |
428 KB |
Output is correct |
14 |
Correct |
74 ms |
416 KB |
Output is correct |
15 |
Correct |
45 ms |
1068 KB |
Output is correct |
16 |
Correct |
58 ms |
1096 KB |
Output is correct |
17 |
Correct |
44 ms |
1152 KB |
Output is correct |
18 |
Correct |
58 ms |
1056 KB |
Output is correct |
19 |
Correct |
51 ms |
1044 KB |
Output is correct |
20 |
Correct |
48 ms |
952 KB |
Output is correct |
21 |
Correct |
57 ms |
592 KB |
Output is correct |
22 |
Correct |
59 ms |
548 KB |
Output is correct |
23 |
Correct |
64 ms |
436 KB |
Output is correct |
24 |
Correct |
41 ms |
572 KB |
Output is correct |
25 |
Correct |
30 ms |
576 KB |
Output is correct |
26 |
Correct |
22 ms |
480 KB |
Output is correct |
27 |
Correct |
26 ms |
820 KB |
Output is correct |
28 |
Correct |
58 ms |
780 KB |
Output is correct |
29 |
Correct |
49 ms |
908 KB |
Output is correct |
30 |
Correct |
23 ms |
944 KB |
Output is correct |
31 |
Correct |
52 ms |
684 KB |
Output is correct |
32 |
Correct |
33 ms |
688 KB |
Output is correct |
33 |
Correct |
63 ms |
456 KB |
Output is correct |
34 |
Correct |
57 ms |
432 KB |
Output is correct |
35 |
Correct |
40 ms |
968 KB |
Output is correct |
36 |
Correct |
60 ms |
808 KB |
Output is correct |
37 |
Correct |
55 ms |
656 KB |
Output is correct |
38 |
Correct |
48 ms |
712 KB |
Output is correct |
39 |
Correct |
49 ms |
736 KB |
Output is correct |
40 |
Correct |
30 ms |
688 KB |
Output is correct |
41 |
Correct |
55 ms |
896 KB |
Output is correct |
42 |
Correct |
41 ms |
864 KB |
Output is correct |
43 |
Correct |
14 ms |
208 KB |
Output is correct |
44 |
Correct |
42 ms |
428 KB |
Output is correct |
45 |
Correct |
40 ms |
1304 KB |
Output is correct |
46 |
Correct |
33 ms |
456 KB |
Output is correct |
47 |
Correct |
35 ms |
436 KB |
Output is correct |
48 |
Correct |
35 ms |
452 KB |
Output is correct |