#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1000 * 1000 + 7;
bool out[N], czy[N], wh[N];
vector<int> cur;
int lft, dif;
int ansd = 1;
int findDif(int n)
{
for(int i = 0; i < n; ++i)
{
move_inside(i);
cur.pb(i);
if(press_button() > 1)
{
cur.pop_back();
move_outside(i);
}
}
int ans = cur.size();
for(int i = 0; i < (int)cur.size(); ++i)
{
out[cur[i]] = true;
move_outside(cur[i]);
}
cur.clear();
return ans;
}
int Check(int x, int n)
{
int ans = 0, xd = 0;
for(int i = 0; i < n; ++i)
{
wh[i] = false;
if(out[i]) continue;
move_inside(i);
czy[i] = true;
ans = press_button();
++xd;
if(ans > x + 1)
{
--xd;
--ans;
wh[i] = true;
czy[i] = false;
move_outside(i);
}
if(xd == dif * (x + 1))
break;
}
//int cp = ans;
//cerr << "xddd " << x << " " << " " << xd << " " << ans << " " << lft << "\n";
if(xd == dif * (x + 1))
{
ans = x + 1;
ansd += x + 1;
}
else
ans = min(ans, x);
for(int i = 0; i < n; ++i)
{
if(xd == dif * (x + 1)) wh[i] = false;
if(out[i]) continue;
if(!czy[i]) continue;
if(xd == dif * (x + 1))
wh[i] = true;
move_outside(i);
czy[i] = false;
/*if(xd != dif * (x + 1) && press_button() < cp)
{
czy[i] = true;
move_inside(i);
wh[i] = true;
}*/
}
/*for(int i = 0; i < n; ++i)
{
if(out[i]) continue;
if(!czy[i]) continue;
move_outside(i);
}*/
//if(xd == dif * (x + 1))
//return ans;
for(int i = 0; i < n; ++i)
if(wh[i])
{
--lft;
out[i] = true;
}
return min(ans, x);
}
int BS(int maks, int n)
{
int p = 0, k = maks;
while(p < k)
{
int s = (p + k) / 2;
if(dif == 1)
return lft;
int x = Check(s, n);
if(x > s)
p = s + 1;
else
k = s;
k = min(k, lft);
}
return p;
}
int min_cardinality(int n)
{
dif = findDif(n);
lft = n - dif;
//cerr << "dif " << dif << "\n";
int m = lft / dif;
int ans = BS(m, n) + ansd;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
2 ms |
2392 KB |
Output is correct |
9 |
Correct |
3 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
2 ms |
2404 KB |
Output is correct |
12 |
Correct |
3 ms |
2392 KB |
Output is correct |
13 |
Correct |
4 ms |
2392 KB |
Output is correct |
14 |
Correct |
3 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
16 |
Correct |
3 ms |
2392 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
3 ms |
2492 KB |
Output is correct |
19 |
Correct |
3 ms |
2496 KB |
Output is correct |
20 |
Correct |
2 ms |
2496 KB |
Output is correct |
21 |
Correct |
2 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
2 ms |
2392 KB |
Output is correct |
9 |
Correct |
3 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
2 ms |
2404 KB |
Output is correct |
12 |
Correct |
3 ms |
2392 KB |
Output is correct |
13 |
Correct |
4 ms |
2392 KB |
Output is correct |
14 |
Correct |
3 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
16 |
Correct |
3 ms |
2392 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
3 ms |
2492 KB |
Output is correct |
19 |
Correct |
3 ms |
2496 KB |
Output is correct |
20 |
Correct |
2 ms |
2496 KB |
Output is correct |
21 |
Correct |
2 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
6 ms |
2496 KB |
Output is correct |
24 |
Correct |
5 ms |
2500 KB |
Output is correct |
25 |
Correct |
11 ms |
2496 KB |
Output is correct |
26 |
Correct |
16 ms |
2496 KB |
Output is correct |
27 |
Correct |
11 ms |
2392 KB |
Output is correct |
28 |
Correct |
7 ms |
2392 KB |
Output is correct |
29 |
Correct |
17 ms |
2500 KB |
Output is correct |
30 |
Correct |
20 ms |
2384 KB |
Output is correct |
31 |
Correct |
9 ms |
2392 KB |
Output is correct |
32 |
Correct |
19 ms |
2496 KB |
Output is correct |
33 |
Correct |
13 ms |
2492 KB |
Output is correct |
34 |
Correct |
18 ms |
2648 KB |
Output is correct |
35 |
Correct |
12 ms |
2392 KB |
Output is correct |
36 |
Correct |
12 ms |
2496 KB |
Output is correct |
37 |
Correct |
12 ms |
2648 KB |
Output is correct |
38 |
Correct |
11 ms |
2648 KB |
Output is correct |
39 |
Correct |
13 ms |
2392 KB |
Output is correct |
40 |
Correct |
5 ms |
2392 KB |
Output is correct |
41 |
Correct |
6 ms |
2496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
11 ms |
2384 KB |
Output is correct |
8 |
Correct |
10 ms |
2648 KB |
Output is correct |
9 |
Correct |
27 ms |
2640 KB |
Output is correct |
10 |
Correct |
25 ms |
2488 KB |
Output is correct |
11 |
Correct |
25 ms |
2392 KB |
Output is correct |
12 |
Correct |
17 ms |
2392 KB |
Output is correct |
13 |
Correct |
46 ms |
2640 KB |
Output is correct |
14 |
Correct |
27 ms |
2392 KB |
Output is correct |
15 |
Correct |
16 ms |
2392 KB |
Output is correct |
16 |
Correct |
17 ms |
2496 KB |
Output is correct |
17 |
Correct |
23 ms |
2500 KB |
Output is correct |
18 |
Correct |
34 ms |
2640 KB |
Output is correct |
19 |
Correct |
32 ms |
2384 KB |
Output is correct |
20 |
Correct |
20 ms |
2388 KB |
Output is correct |
21 |
Correct |
32 ms |
2484 KB |
Output is correct |
22 |
Correct |
20 ms |
2392 KB |
Output is correct |
23 |
Correct |
32 ms |
2640 KB |
Output is correct |
24 |
Correct |
18 ms |
2392 KB |
Output is correct |
25 |
Correct |
12 ms |
2380 KB |
Output is correct |
26 |
Correct |
9 ms |
2488 KB |
Output is correct |
27 |
Correct |
38 ms |
2640 KB |
Output is correct |
28 |
Correct |
18 ms |
2384 KB |
Output is correct |
29 |
Correct |
37 ms |
2468 KB |
Output is correct |
30 |
Correct |
25 ms |
2392 KB |
Output is correct |
31 |
Correct |
29 ms |
2384 KB |
Output is correct |
32 |
Correct |
27 ms |
2640 KB |
Output is correct |
33 |
Partially correct |
33 ms |
2392 KB |
Output is partially correct |
34 |
Correct |
24 ms |
2484 KB |
Output is correct |
35 |
Correct |
26 ms |
2496 KB |
Output is correct |
36 |
Correct |
38 ms |
2232 KB |
Output is correct |
37 |
Correct |
28 ms |
2384 KB |
Output is correct |
38 |
Correct |
50 ms |
2492 KB |
Output is correct |
39 |
Correct |
24 ms |
2392 KB |
Output is correct |
40 |
Correct |
22 ms |
2640 KB |
Output is correct |
41 |
Correct |
25 ms |
2640 KB |
Output is correct |
42 |
Correct |
25 ms |
2644 KB |
Output is correct |
43 |
Correct |
7 ms |
2392 KB |
Output is correct |
44 |
Correct |
17 ms |
2480 KB |
Output is correct |
45 |
Correct |
21 ms |
2384 KB |
Output is correct |
46 |
Correct |
14 ms |
2496 KB |
Output is correct |
47 |
Correct |
13 ms |
2384 KB |
Output is correct |
48 |
Correct |
13 ms |
2392 KB |
Output is correct |