#include<bits/stdc++.h>
#include "insects.h"
using namespace std;
mt19937 gen(time(0));
int groups, lft;
vector<bool> done;
int get_groups(int N){
int groups = 0;
for(int i = 0; i < N; i++){
move_inside(i);
int rep = press_button();
if(rep > 1) { move_outside(i); }
else { groups++; done[i] = 1; }
}
return groups;
}
int choose_best(int lo, int hi){
//If I choose mid. Then in the case that all the groups are of size at least mid,
//I discard (mid - lo + 1) * groups.
//In the other case, I discard left - chosen (and chosen can be at most (mid - lo + 1) * groups).
//So I want min((mid - lo + 1) * groups, left - (mid - lo + 1) * groups) to be the maximum.
int x = lft / 2;
int bst = x / groups;
int mn1 = min(bst * groups, lft - bst * groups + 1);
bst++;
int mn2 = min(bst * groups, lft - bst * groups + 1);
if(mn1 < mn2) bst--;
return max(lo, min(hi, lo + bst - 1));
}
int min_cardinality(int N) {
done.assign(N, 0);
int ans = 1;
groups = get_groups(N);
lft = N - groups;
int cnt = groups;
int lo = 2;
int hi = N / groups;
while(lo <= hi && lft > 0) {
int mid = choose_best(lo, hi);
vector<int> good, bad;
vector<int> possible;
for(int i = 0; i < N; i++) {
if(!done[i]) possible.push_back(i);
}
while((int)possible.size() > 0){
if((cnt + (int)good.size()) == mid * groups) {
bad.push_back(possible.back());
possible.pop_back();
continue;
}
int ind = gen() % ((int)possible.size());
int i = possible[ind];
move_inside(i);
int rep = press_button();
if(rep > mid) {
bad.push_back(i);
move_outside(i);
} else { good.push_back(i); }
if(ind != (int)possible.size() - 1) swap(possible[ind], possible[(int)possible.size() - 1]);
possible.pop_back();
}
if((int)good.size() + cnt == mid * groups) {
ans = mid;
lo = mid + 1;
for(int x : good) done[x] = 1;
cnt += (int)good.size();
lft -= (int)good.size();
} else {
hi = mid - 1;
for(int x : good) move_outside(x);
for(int x : bad) done[x] = 1;
lft -= (int)bad.size();
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
4 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
4 ms |
208 KB |
Output is correct |
18 |
Correct |
6 ms |
208 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
3 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
4 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
4 ms |
208 KB |
Output is correct |
18 |
Correct |
6 ms |
208 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
3 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
12 ms |
208 KB |
Output is correct |
24 |
Correct |
8 ms |
208 KB |
Output is correct |
25 |
Correct |
13 ms |
208 KB |
Output is correct |
26 |
Correct |
26 ms |
208 KB |
Output is correct |
27 |
Correct |
14 ms |
208 KB |
Output is correct |
28 |
Correct |
6 ms |
208 KB |
Output is correct |
29 |
Correct |
26 ms |
208 KB |
Output is correct |
30 |
Correct |
21 ms |
296 KB |
Output is correct |
31 |
Correct |
10 ms |
312 KB |
Output is correct |
32 |
Correct |
22 ms |
208 KB |
Output is correct |
33 |
Correct |
17 ms |
300 KB |
Output is correct |
34 |
Correct |
17 ms |
208 KB |
Output is correct |
35 |
Correct |
23 ms |
208 KB |
Output is correct |
36 |
Correct |
20 ms |
208 KB |
Output is correct |
37 |
Correct |
24 ms |
296 KB |
Output is correct |
38 |
Correct |
27 ms |
208 KB |
Output is correct |
39 |
Correct |
23 ms |
300 KB |
Output is correct |
40 |
Correct |
10 ms |
208 KB |
Output is correct |
41 |
Correct |
9 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
18 ms |
284 KB |
Output is correct |
8 |
Correct |
13 ms |
208 KB |
Output is correct |
9 |
Correct |
38 ms |
296 KB |
Output is correct |
10 |
Correct |
34 ms |
328 KB |
Output is correct |
11 |
Correct |
17 ms |
208 KB |
Output is correct |
12 |
Correct |
23 ms |
208 KB |
Output is correct |
13 |
Correct |
39 ms |
208 KB |
Output is correct |
14 |
Correct |
48 ms |
208 KB |
Output is correct |
15 |
Correct |
31 ms |
308 KB |
Output is correct |
16 |
Correct |
36 ms |
328 KB |
Output is correct |
17 |
Correct |
31 ms |
296 KB |
Output is correct |
18 |
Correct |
27 ms |
208 KB |
Output is correct |
19 |
Correct |
30 ms |
304 KB |
Output is correct |
20 |
Correct |
35 ms |
208 KB |
Output is correct |
21 |
Correct |
47 ms |
300 KB |
Output is correct |
22 |
Correct |
30 ms |
304 KB |
Output is correct |
23 |
Correct |
53 ms |
300 KB |
Output is correct |
24 |
Correct |
22 ms |
308 KB |
Output is correct |
25 |
Correct |
18 ms |
296 KB |
Output is correct |
26 |
Correct |
16 ms |
208 KB |
Output is correct |
27 |
Correct |
37 ms |
304 KB |
Output is correct |
28 |
Correct |
30 ms |
292 KB |
Output is correct |
29 |
Correct |
39 ms |
296 KB |
Output is correct |
30 |
Correct |
16 ms |
296 KB |
Output is correct |
31 |
Correct |
38 ms |
304 KB |
Output is correct |
32 |
Correct |
45 ms |
304 KB |
Output is correct |
33 |
Partially correct |
51 ms |
208 KB |
Output is partially correct |
34 |
Partially correct |
56 ms |
292 KB |
Output is partially correct |
35 |
Correct |
18 ms |
432 KB |
Output is correct |
36 |
Correct |
41 ms |
300 KB |
Output is correct |
37 |
Correct |
39 ms |
300 KB |
Output is correct |
38 |
Correct |
31 ms |
208 KB |
Output is correct |
39 |
Correct |
41 ms |
208 KB |
Output is correct |
40 |
Correct |
41 ms |
208 KB |
Output is correct |
41 |
Correct |
24 ms |
296 KB |
Output is correct |
42 |
Correct |
40 ms |
208 KB |
Output is correct |
43 |
Correct |
7 ms |
300 KB |
Output is correct |
44 |
Correct |
26 ms |
208 KB |
Output is correct |
45 |
Correct |
27 ms |
300 KB |
Output is correct |
46 |
Correct |
20 ms |
208 KB |
Output is correct |
47 |
Correct |
25 ms |
208 KB |
Output is correct |
48 |
Correct |
18 ms |
296 KB |
Output is correct |