#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 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);
}
}
//cerr << "xddd " << x << " " << " " << xd << " " << ans << " " << lft << "\n";
if(xd == dif * (x + 1))
ans = x + 1;
else
ans = min(ans, x);
for(int i = 0; i < n; ++i)
{
if(out[i]) continue;
if(czy[i])
move_outside(i);
czy[i] = false;
}
if(ans == x + 1)
return ans;
for(int i = 0; i < n; ++i)
if(wh[i])
{
--lft;
out[i] = true;
}
return ans;
}
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);
return ans + 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
5 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
3 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
4 ms |
2392 KB |
Output is correct |
13 |
Correct |
3 ms |
2392 KB |
Output is correct |
14 |
Correct |
7 ms |
2500 KB |
Output is correct |
15 |
Correct |
5 ms |
2392 KB |
Output is correct |
16 |
Correct |
4 ms |
2392 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
3 ms |
2392 KB |
Output is correct |
19 |
Correct |
3 ms |
2392 KB |
Output is correct |
20 |
Correct |
3 ms |
2392 KB |
Output is correct |
21 |
Correct |
2 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
5 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
3 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
4 ms |
2392 KB |
Output is correct |
13 |
Correct |
3 ms |
2392 KB |
Output is correct |
14 |
Correct |
7 ms |
2500 KB |
Output is correct |
15 |
Correct |
5 ms |
2392 KB |
Output is correct |
16 |
Correct |
4 ms |
2392 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
3 ms |
2392 KB |
Output is correct |
19 |
Correct |
3 ms |
2392 KB |
Output is correct |
20 |
Correct |
3 ms |
2392 KB |
Output is correct |
21 |
Correct |
2 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
5 ms |
2504 KB |
Output is correct |
24 |
Correct |
6 ms |
2392 KB |
Output is correct |
25 |
Correct |
28 ms |
2392 KB |
Output is correct |
26 |
Correct |
34 ms |
2648 KB |
Output is correct |
27 |
Correct |
18 ms |
2648 KB |
Output is correct |
28 |
Correct |
5 ms |
2392 KB |
Output is correct |
29 |
Correct |
13 ms |
2492 KB |
Output is correct |
30 |
Correct |
10 ms |
2392 KB |
Output is correct |
31 |
Correct |
52 ms |
2496 KB |
Output is correct |
32 |
Correct |
45 ms |
2392 KB |
Output is correct |
33 |
Correct |
49 ms |
2384 KB |
Output is correct |
34 |
Correct |
40 ms |
2476 KB |
Output is correct |
35 |
Correct |
33 ms |
2392 KB |
Output is correct |
36 |
Correct |
40 ms |
2648 KB |
Output is correct |
37 |
Correct |
18 ms |
2392 KB |
Output is correct |
38 |
Correct |
14 ms |
2500 KB |
Output is correct |
39 |
Correct |
15 ms |
2392 KB |
Output is correct |
40 |
Correct |
9 ms |
2648 KB |
Output is correct |
41 |
Correct |
5 ms |
2496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
2392 KB |
Output is correct |
7 |
Correct |
9 ms |
2228 KB |
Output is correct |
8 |
Correct |
8 ms |
2384 KB |
Output is correct |
9 |
Partially correct |
87 ms |
2708 KB |
Output is partially correct |
10 |
Partially correct |
49 ms |
2640 KB |
Output is partially correct |
11 |
Correct |
29 ms |
2648 KB |
Output is correct |
12 |
Correct |
13 ms |
2392 KB |
Output is correct |
13 |
Correct |
25 ms |
2384 KB |
Output is correct |
14 |
Correct |
20 ms |
2648 KB |
Output is correct |
15 |
Partially correct |
109 ms |
2724 KB |
Output is partially correct |
16 |
Partially correct |
88 ms |
2728 KB |
Output is partially correct |
17 |
Partially correct |
96 ms |
2724 KB |
Output is partially correct |
18 |
Partially correct |
86 ms |
2744 KB |
Output is partially correct |
19 |
Partially correct |
103 ms |
2632 KB |
Output is partially correct |
20 |
Partially correct |
74 ms |
2628 KB |
Output is partially correct |
21 |
Partially correct |
63 ms |
2732 KB |
Output is partially correct |
22 |
Partially correct |
44 ms |
2232 KB |
Output is partially correct |
23 |
Correct |
22 ms |
2236 KB |
Output is correct |
24 |
Correct |
21 ms |
2480 KB |
Output is correct |
25 |
Correct |
12 ms |
2480 KB |
Output is correct |
26 |
Correct |
11 ms |
2736 KB |
Output is correct |
27 |
Partially correct |
42 ms |
2472 KB |
Output is partially correct |
28 |
Partially correct |
87 ms |
2476 KB |
Output is partially correct |
29 |
Partially correct |
90 ms |
2492 KB |
Output is partially correct |
30 |
Partially correct |
89 ms |
2648 KB |
Output is partially correct |
31 |
Partially correct |
40 ms |
2392 KB |
Output is partially correct |
32 |
Partially correct |
42 ms |
2640 KB |
Output is partially correct |
33 |
Partially correct |
28 ms |
2648 KB |
Output is partially correct |
34 |
Partially correct |
25 ms |
2640 KB |
Output is partially correct |
35 |
Partially correct |
72 ms |
2384 KB |
Output is partially correct |
36 |
Partially correct |
58 ms |
2728 KB |
Output is partially correct |
37 |
Partially correct |
63 ms |
2648 KB |
Output is partially correct |
38 |
Partially correct |
46 ms |
2728 KB |
Output is partially correct |
39 |
Partially correct |
66 ms |
2728 KB |
Output is partially correct |
40 |
Partially correct |
48 ms |
2640 KB |
Output is partially correct |
41 |
Partially correct |
67 ms |
2476 KB |
Output is partially correct |
42 |
Partially correct |
78 ms |
2480 KB |
Output is partially correct |
43 |
Correct |
4 ms |
2392 KB |
Output is correct |
44 |
Correct |
19 ms |
2384 KB |
Output is correct |
45 |
Partially correct |
113 ms |
2708 KB |
Output is partially correct |
46 |
Correct |
16 ms |
2384 KB |
Output is correct |
47 |
Correct |
14 ms |
2640 KB |
Output is correct |
48 |
Correct |
14 ms |
2392 KB |
Output is correct |