#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rnd(2);
int min_cardinality(vector<int> x)
{
shuffle(x.begin(), x.end(), rnd);
int N = x.size();
int add2 = 0;
int add1 = 0;
vector<int>y;
vector<int>z;
int lo, hi;
int c = 0;
auto cnt = [&](int m)->int
{
vector<int>v;
y = {};
z = {};
int k = 0;
bool jau = false;
int liko = (int)x.size();
for (int i : x)
{
if (!jau)
v.push_back(i);
if (!jau)
move_inside(i);
if (!jau)
k = press_button();
if (k + add1 == m + 1 || jau)
{
if (!jau)
v.pop_back();
if (!jau)
move_outside(i);
y.push_back(i);
}
liko--;
if (c != 0)
if ((int)v.size() + add2 == m * c)
jau = true;
}
z = v;
int r = v.size();
for (int i : v)
move_outside(i);
return add2 + r;
};
c = cnt(1);
if (c * 2 > N)
return 1;
{
x = y;
add2 = c;
add1 = 1;
}
lo = 1;
hi = N / c;
double bias = 1;
bool fst = true;
while (lo < hi)
{
int m = round((lo * bias + hi * 1.0) / (bias + 1));
m = max(m, lo + 1);
m = min(m, hi);
int k = cnt(m);
if (k == m * c)
{
lo = m;
x = y;
add2 = m * c;
add1 = m;
}
else
{
if (m * c - k < m)
lo = max(lo, m - (m * c - k));
x = z;
hi = m - 1;
}
fst = false;
}
return lo;
}
int min_cardinality(int N) {
vector<int>v;
for (int i = 0; i < N; i++)
v.push_back(i);
return min_cardinality(v);
}
Compilation message
insects.cpp: In function 'int min_cardinality(std::vector<int>)':
insects.cpp:61:10: warning: variable 'fst' set but not used [-Wunused-but-set-variable]
61 | bool fst = true;
| ^~~
# |
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 |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
4 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 |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
6 ms |
208 KB |
Output is correct |
15 |
Correct |
5 ms |
208 KB |
Output is correct |
16 |
Correct |
7 ms |
208 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
208 KB |
Output is correct |
19 |
Correct |
6 ms |
208 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
2 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 |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
4 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 |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
6 ms |
208 KB |
Output is correct |
15 |
Correct |
5 ms |
208 KB |
Output is correct |
16 |
Correct |
7 ms |
208 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
208 KB |
Output is correct |
19 |
Correct |
6 ms |
208 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
8 ms |
208 KB |
Output is correct |
24 |
Correct |
8 ms |
208 KB |
Output is correct |
25 |
Correct |
19 ms |
208 KB |
Output is correct |
26 |
Correct |
23 ms |
316 KB |
Output is correct |
27 |
Correct |
18 ms |
316 KB |
Output is correct |
28 |
Correct |
7 ms |
312 KB |
Output is correct |
29 |
Correct |
19 ms |
208 KB |
Output is correct |
30 |
Correct |
23 ms |
208 KB |
Output is correct |
31 |
Correct |
22 ms |
324 KB |
Output is correct |
32 |
Correct |
17 ms |
320 KB |
Output is correct |
33 |
Correct |
25 ms |
316 KB |
Output is correct |
34 |
Correct |
21 ms |
316 KB |
Output is correct |
35 |
Correct |
23 ms |
208 KB |
Output is correct |
36 |
Correct |
21 ms |
208 KB |
Output is correct |
37 |
Correct |
32 ms |
208 KB |
Output is correct |
38 |
Correct |
26 ms |
208 KB |
Output is correct |
39 |
Correct |
21 ms |
316 KB |
Output is correct |
40 |
Correct |
15 ms |
372 KB |
Output is correct |
41 |
Correct |
10 ms |
308 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 |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
36 ms |
324 KB |
Output is correct |
8 |
Correct |
17 ms |
324 KB |
Output is correct |
9 |
Correct |
46 ms |
324 KB |
Output is correct |
10 |
Correct |
26 ms |
324 KB |
Output is correct |
11 |
Correct |
42 ms |
208 KB |
Output is correct |
12 |
Correct |
28 ms |
208 KB |
Output is correct |
13 |
Correct |
49 ms |
336 KB |
Output is correct |
14 |
Correct |
43 ms |
208 KB |
Output is correct |
15 |
Correct |
45 ms |
320 KB |
Output is correct |
16 |
Correct |
36 ms |
320 KB |
Output is correct |
17 |
Correct |
32 ms |
320 KB |
Output is correct |
18 |
Correct |
35 ms |
336 KB |
Output is correct |
19 |
Correct |
46 ms |
208 KB |
Output is correct |
20 |
Correct |
41 ms |
320 KB |
Output is correct |
21 |
Correct |
52 ms |
320 KB |
Output is correct |
22 |
Correct |
36 ms |
336 KB |
Output is correct |
23 |
Correct |
47 ms |
316 KB |
Output is correct |
24 |
Correct |
41 ms |
324 KB |
Output is correct |
25 |
Correct |
21 ms |
208 KB |
Output is correct |
26 |
Correct |
17 ms |
320 KB |
Output is correct |
27 |
Correct |
47 ms |
208 KB |
Output is correct |
28 |
Correct |
54 ms |
328 KB |
Output is correct |
29 |
Correct |
44 ms |
320 KB |
Output is correct |
30 |
Correct |
46 ms |
316 KB |
Output is correct |
31 |
Correct |
37 ms |
312 KB |
Output is correct |
32 |
Correct |
42 ms |
336 KB |
Output is correct |
33 |
Correct |
42 ms |
328 KB |
Output is correct |
34 |
Correct |
38 ms |
312 KB |
Output is correct |
35 |
Correct |
38 ms |
324 KB |
Output is correct |
36 |
Correct |
46 ms |
316 KB |
Output is correct |
37 |
Correct |
43 ms |
312 KB |
Output is correct |
38 |
Correct |
60 ms |
320 KB |
Output is correct |
39 |
Correct |
28 ms |
320 KB |
Output is correct |
40 |
Correct |
51 ms |
208 KB |
Output is correct |
41 |
Correct |
63 ms |
324 KB |
Output is correct |
42 |
Correct |
41 ms |
208 KB |
Output is correct |
43 |
Correct |
10 ms |
312 KB |
Output is correct |
44 |
Correct |
42 ms |
208 KB |
Output is correct |
45 |
Correct |
33 ms |
320 KB |
Output is correct |
46 |
Correct |
22 ms |
320 KB |
Output is correct |
47 |
Correct |
31 ms |
324 KB |
Output is correct |
48 |
Correct |
30 ms |
316 KB |
Output is correct |