#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];
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)
{
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)
{
if(out[i]) continue;
move_inside(i);
czy[i] = true;
ans = press_button();
++xd;
if(ans > x + 1)
{
--xd;
--ans;
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_inside(i);
}
int cp = press_button();
for(int i = 0; i < n; ++i)
{
if(out[i]) continue;
move_outside(i);
czy[i] = false;
if(press_button() < cp)
{
czy[i] = true;
move_inside(i);
}
}
for(int i = 0; i < n; ++i)
{
if(out[i]) continue;
if(!czy[i]) continue;
move_outside(i);
out[i] = true;
}
--dif;
lft -= cp;
return ans;
}
int BS(int maks, int n)
{
int p = 1, 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;
//cerr << "dif " << dif << "\n";
int m = n;
int ans = BS(m, n);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
15 ms |
344 KB |
Output is correct |
8 |
Correct |
12 ms |
344 KB |
Output is correct |
9 |
Correct |
8 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
344 KB |
Output is correct |
12 |
Correct |
6 ms |
344 KB |
Output is correct |
13 |
Correct |
12 ms |
344 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
8 ms |
344 KB |
Output is correct |
16 |
Correct |
12 ms |
344 KB |
Output is correct |
17 |
Correct |
13 ms |
452 KB |
Output is correct |
18 |
Correct |
12 ms |
344 KB |
Output is correct |
19 |
Correct |
8 ms |
344 KB |
Output is correct |
20 |
Correct |
12 ms |
344 KB |
Output is correct |
21 |
Correct |
17 ms |
344 KB |
Output is correct |
22 |
Correct |
14 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
15 ms |
344 KB |
Output is correct |
8 |
Correct |
12 ms |
344 KB |
Output is correct |
9 |
Correct |
8 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
344 KB |
Output is correct |
12 |
Correct |
6 ms |
344 KB |
Output is correct |
13 |
Correct |
12 ms |
344 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
8 ms |
344 KB |
Output is correct |
16 |
Correct |
12 ms |
344 KB |
Output is correct |
17 |
Correct |
13 ms |
452 KB |
Output is correct |
18 |
Correct |
12 ms |
344 KB |
Output is correct |
19 |
Correct |
8 ms |
344 KB |
Output is correct |
20 |
Correct |
12 ms |
344 KB |
Output is correct |
21 |
Correct |
17 ms |
344 KB |
Output is correct |
22 |
Correct |
14 ms |
344 KB |
Output is correct |
23 |
Correct |
5 ms |
344 KB |
Output is correct |
24 |
Correct |
132 ms |
428 KB |
Output is correct |
25 |
Correct |
115 ms |
344 KB |
Output is correct |
26 |
Correct |
96 ms |
344 KB |
Output is correct |
27 |
Correct |
9 ms |
344 KB |
Output is correct |
28 |
Correct |
70 ms |
592 KB |
Output is correct |
29 |
Correct |
29 ms |
344 KB |
Output is correct |
30 |
Correct |
97 ms |
592 KB |
Output is correct |
31 |
Correct |
40 ms |
436 KB |
Output is correct |
32 |
Correct |
41 ms |
592 KB |
Output is correct |
33 |
Correct |
78 ms |
592 KB |
Output is correct |
34 |
Correct |
77 ms |
600 KB |
Output is correct |
35 |
Correct |
72 ms |
436 KB |
Output is correct |
36 |
Correct |
112 ms |
440 KB |
Output is correct |
37 |
Correct |
107 ms |
344 KB |
Output is correct |
38 |
Correct |
117 ms |
588 KB |
Output is correct |
39 |
Correct |
143 ms |
440 KB |
Output is correct |
40 |
Correct |
108 ms |
344 KB |
Output is correct |
41 |
Correct |
114 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Partially correct |
0 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
0 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
1 ms |
344 KB |
Output is partially correct |
6 |
Partially correct |
1 ms |
344 KB |
Output is partially correct |
7 |
Correct |
9 ms |
344 KB |
Output is correct |
8 |
Incorrect |
200 ms |
452 KB |
Too many queries. |
9 |
Halted |
0 ms |
0 KB |
- |