#include <bits/stdc++.h>
#ifndef SKY
#include "insects.h"
#endif // SKY
using namespace std;
#define N 2010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back
int n;
#ifdef SKY
int type[N],chon[N],cnt[N];
void move_inside(int i)
{
chon[i]=1;
}
void move_outside(int i)
{
chon[i]=0;
}
int press_button()
{
int res=0;
memset(cnt,0,sizeof(cnt));
for(int i=0;i<n;i++)
if(chon[i]==1)
res=max(res,++cnt[type[i]]);
return res;
}
#endif // SKY
int dp[N],ktr[N],sl,ans=1;
vector<int>s,luu;
bool check(int x)
{
luu=s;
int val=ans;
for(int i=0;i<n;i++)
if(ktr[i]==0&&dp[i]<=x)
{
move_inside(i);
int t=press_button();
if(t==x+1)
{
move_outside(i);
dp[i]=max(dp[i],x+1);
continue;
}
luu.pb(i);
if(t==val+1)
{
val=t;
dp[i]=max(dp[i],t);
}
}
return(luu.size()==x*sl);
}
int min_cardinality(int NNN)
{
n=NNN;
for(int i=0;i<n;i++)
{
move_inside(i);
if(press_button()<=1)
{
s.pb(i);
ktr[i]=1;
}else
{
move_outside(i);
}
}
sl=s.size();
if(sl==1)
return n;
if(sl*2>n)
return 1;
int l=2,r=n/sl;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid))
{
ans=mid;
l=mid+1;
s=luu;
for(auto i:s)
ktr[i]=1;
}else
{
while(luu.back()!=s.back())
{
move_outside(luu.back());
luu.pop_back();
}
r=mid-1;
}
}
return ans;
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>type[i];
cout<<min_cardinality(n);
return 0;
}
#endif
Compilation message
insects.cpp: In function 'bool check(int)':
insects.cpp:67:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
67 | return(luu.size()==x*sl);
| ~~~~~~~~~~^~~~~~
# |
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 |
2 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 |
6 ms |
304 KB |
Output is correct |
10 |
Correct |
8 ms |
300 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
9 ms |
208 KB |
Output is correct |
13 |
Correct |
7 ms |
304 KB |
Output is correct |
14 |
Correct |
6 ms |
312 KB |
Output is correct |
15 |
Correct |
6 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
308 KB |
Output is correct |
17 |
Correct |
3 ms |
300 KB |
Output is correct |
18 |
Correct |
6 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 |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
300 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 |
2 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 |
6 ms |
304 KB |
Output is correct |
10 |
Correct |
8 ms |
300 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
9 ms |
208 KB |
Output is correct |
13 |
Correct |
7 ms |
304 KB |
Output is correct |
14 |
Correct |
6 ms |
312 KB |
Output is correct |
15 |
Correct |
6 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
308 KB |
Output is correct |
17 |
Correct |
3 ms |
300 KB |
Output is correct |
18 |
Correct |
6 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 |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
300 KB |
Output is correct |
23 |
Correct |
13 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
308 KB |
Output is correct |
25 |
Correct |
21 ms |
416 KB |
Output is correct |
26 |
Correct |
22 ms |
208 KB |
Output is correct |
27 |
Correct |
10 ms |
208 KB |
Output is correct |
28 |
Correct |
9 ms |
208 KB |
Output is correct |
29 |
Correct |
12 ms |
304 KB |
Output is correct |
30 |
Correct |
31 ms |
304 KB |
Output is correct |
31 |
Correct |
33 ms |
296 KB |
Output is correct |
32 |
Correct |
27 ms |
300 KB |
Output is correct |
33 |
Correct |
32 ms |
312 KB |
Output is correct |
34 |
Correct |
25 ms |
296 KB |
Output is correct |
35 |
Correct |
25 ms |
208 KB |
Output is correct |
36 |
Correct |
25 ms |
300 KB |
Output is correct |
37 |
Correct |
31 ms |
292 KB |
Output is correct |
38 |
Correct |
20 ms |
296 KB |
Output is correct |
39 |
Correct |
21 ms |
208 KB |
Output is correct |
40 |
Correct |
13 ms |
208 KB |
Output is correct |
41 |
Correct |
11 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
236 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
23 ms |
208 KB |
Output is correct |
8 |
Correct |
20 ms |
208 KB |
Output is correct |
9 |
Correct |
47 ms |
544 KB |
Output is correct |
10 |
Correct |
59 ms |
308 KB |
Output is correct |
11 |
Correct |
35 ms |
208 KB |
Output is correct |
12 |
Correct |
25 ms |
308 KB |
Output is correct |
13 |
Correct |
54 ms |
300 KB |
Output is correct |
14 |
Correct |
36 ms |
308 KB |
Output is correct |
15 |
Correct |
59 ms |
288 KB |
Output is correct |
16 |
Correct |
60 ms |
312 KB |
Output is correct |
17 |
Correct |
43 ms |
292 KB |
Output is correct |
18 |
Correct |
43 ms |
332 KB |
Output is correct |
19 |
Correct |
62 ms |
300 KB |
Output is correct |
20 |
Correct |
49 ms |
208 KB |
Output is correct |
21 |
Correct |
44 ms |
328 KB |
Output is correct |
22 |
Correct |
47 ms |
428 KB |
Output is correct |
23 |
Correct |
49 ms |
208 KB |
Output is correct |
24 |
Correct |
42 ms |
304 KB |
Output is correct |
25 |
Correct |
30 ms |
308 KB |
Output is correct |
26 |
Correct |
20 ms |
208 KB |
Output is correct |
27 |
Correct |
45 ms |
316 KB |
Output is correct |
28 |
Correct |
52 ms |
296 KB |
Output is correct |
29 |
Partially correct |
40 ms |
308 KB |
Output is partially correct |
30 |
Partially correct |
66 ms |
300 KB |
Output is partially correct |
31 |
Correct |
38 ms |
300 KB |
Output is correct |
32 |
Correct |
48 ms |
312 KB |
Output is correct |
33 |
Correct |
47 ms |
296 KB |
Output is correct |
34 |
Correct |
51 ms |
284 KB |
Output is correct |
35 |
Partially correct |
49 ms |
292 KB |
Output is partially correct |
36 |
Partially correct |
53 ms |
308 KB |
Output is partially correct |
37 |
Correct |
61 ms |
308 KB |
Output is correct |
38 |
Correct |
61 ms |
296 KB |
Output is correct |
39 |
Correct |
47 ms |
296 KB |
Output is correct |
40 |
Correct |
54 ms |
312 KB |
Output is correct |
41 |
Partially correct |
53 ms |
300 KB |
Output is partially correct |
42 |
Partially correct |
47 ms |
292 KB |
Output is partially correct |
43 |
Correct |
12 ms |
300 KB |
Output is correct |
44 |
Correct |
53 ms |
292 KB |
Output is correct |
45 |
Correct |
29 ms |
292 KB |
Output is correct |
46 |
Correct |
25 ms |
312 KB |
Output is correct |
47 |
Correct |
24 ms |
292 KB |
Output is correct |
48 |
Correct |
25 ms |
208 KB |
Output is correct |