#include <bits/stdc++.h>
#include "insects.h"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define ll long long
using namespace std;
const int N = 2e5 + 5;
//int n,a[N],b[N];
// void move_inside(int i){
// ++b[a[i]];
// }
// void move_outside(int i){
// --b[a[i]];
// }
// int press_button(){
// int mx = 0;
// rep(i,1,n)mx = max(mx,b[i]);
// return mx;
// }
int min_cardinality(int n){
mt19937 mt(19260817);
int cnt = 0;
vi vis(n,0);
rep(i,0,n - 1){
move_inside(i);
//appeared before
if(i && press_button() > 1)move_outside(i);
else vis[i] = 1,cnt++;
}
int tmp = cnt,L = 2,R = n / cnt,ans = 1;
vi rem,p(n);
iota(ALL(p),0);
while(L <= R){
int k = (L + R) >> 1;
shuffle(ALL(p),mt);
rep(t,0,n - 1){
int i = p[t];
if(vis[i])continue;
move_inside(i);
if(press_button() > k){
move_outside(i);
rem.pb(i);
}
else tmp++;
if(tmp == k * cnt){//all kind are in the bucket
rep(j,t + 1,n - 1)if(!vis[p[j]]){
rem.pb(p[j]);
}
//stop the meaningless process
break;
}
}
if(k * cnt == tmp){
ans = k,L = k + 1;
//if greater than k, you don't need to throw away the insects in your bucket.
//You only need to consider the insects left.
rep(i,0,n - 1)vis[i] = 1;
for(int x : rem)vis[x] = 0;
}else{
R = k - 1;
//if the answer is smaller than k,you won't need the (k+1)th insects
for(int x : rem)vis[x] = 1;
rep(i,0,n - 1)if(!vis[i]){
move_outside(i);
tmp--;
}
}
rem.clear();
}
return ans;
}
// int main(){
// cin >> n;
// rep(i,0,n - 1)cin >> a[i];
// cout << min_cardinality(n) << '\n';
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
4 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
300 KB |
Output is correct |
9 |
Correct |
4 ms |
304 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
300 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
3 ms |
300 KB |
Output is correct |
16 |
Correct |
5 ms |
300 KB |
Output is correct |
17 |
Correct |
5 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
208 KB |
Output is correct |
19 |
Correct |
5 ms |
208 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
5 ms |
304 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
4 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
300 KB |
Output is correct |
9 |
Correct |
4 ms |
304 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
300 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
3 ms |
300 KB |
Output is correct |
16 |
Correct |
5 ms |
300 KB |
Output is correct |
17 |
Correct |
5 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
208 KB |
Output is correct |
19 |
Correct |
5 ms |
208 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
5 ms |
304 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
13 ms |
292 KB |
Output is correct |
24 |
Correct |
7 ms |
208 KB |
Output is correct |
25 |
Correct |
16 ms |
308 KB |
Output is correct |
26 |
Correct |
19 ms |
308 KB |
Output is correct |
27 |
Correct |
24 ms |
288 KB |
Output is correct |
28 |
Correct |
11 ms |
208 KB |
Output is correct |
29 |
Correct |
25 ms |
300 KB |
Output is correct |
30 |
Correct |
30 ms |
308 KB |
Output is correct |
31 |
Correct |
10 ms |
308 KB |
Output is correct |
32 |
Correct |
20 ms |
208 KB |
Output is correct |
33 |
Correct |
15 ms |
284 KB |
Output is correct |
34 |
Correct |
22 ms |
308 KB |
Output is correct |
35 |
Correct |
24 ms |
208 KB |
Output is correct |
36 |
Correct |
25 ms |
208 KB |
Output is correct |
37 |
Correct |
18 ms |
208 KB |
Output is correct |
38 |
Correct |
18 ms |
312 KB |
Output is correct |
39 |
Correct |
15 ms |
208 KB |
Output is correct |
40 |
Correct |
11 ms |
208 KB |
Output is correct |
41 |
Correct |
7 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
39 ms |
304 KB |
Output is correct |
8 |
Correct |
12 ms |
292 KB |
Output is correct |
9 |
Correct |
20 ms |
296 KB |
Output is correct |
10 |
Correct |
42 ms |
304 KB |
Output is correct |
11 |
Correct |
37 ms |
308 KB |
Output is correct |
12 |
Correct |
32 ms |
300 KB |
Output is correct |
13 |
Correct |
53 ms |
288 KB |
Output is correct |
14 |
Correct |
42 ms |
288 KB |
Output is correct |
15 |
Correct |
32 ms |
296 KB |
Output is correct |
16 |
Correct |
28 ms |
296 KB |
Output is correct |
17 |
Correct |
42 ms |
296 KB |
Output is correct |
18 |
Correct |
34 ms |
208 KB |
Output is correct |
19 |
Correct |
38 ms |
304 KB |
Output is correct |
20 |
Correct |
59 ms |
208 KB |
Output is correct |
21 |
Correct |
59 ms |
304 KB |
Output is correct |
22 |
Correct |
53 ms |
288 KB |
Output is correct |
23 |
Correct |
32 ms |
304 KB |
Output is correct |
24 |
Correct |
43 ms |
304 KB |
Output is correct |
25 |
Correct |
20 ms |
304 KB |
Output is correct |
26 |
Correct |
21 ms |
288 KB |
Output is correct |
27 |
Correct |
36 ms |
208 KB |
Output is correct |
28 |
Correct |
43 ms |
208 KB |
Output is correct |
29 |
Correct |
35 ms |
292 KB |
Output is correct |
30 |
Correct |
34 ms |
304 KB |
Output is correct |
31 |
Correct |
54 ms |
304 KB |
Output is correct |
32 |
Correct |
46 ms |
304 KB |
Output is correct |
33 |
Correct |
56 ms |
300 KB |
Output is correct |
34 |
Correct |
43 ms |
292 KB |
Output is correct |
35 |
Correct |
42 ms |
420 KB |
Output is correct |
36 |
Correct |
45 ms |
296 KB |
Output is correct |
37 |
Correct |
23 ms |
288 KB |
Output is correct |
38 |
Correct |
53 ms |
292 KB |
Output is correct |
39 |
Correct |
42 ms |
304 KB |
Output is correct |
40 |
Correct |
35 ms |
300 KB |
Output is correct |
41 |
Correct |
47 ms |
300 KB |
Output is correct |
42 |
Correct |
49 ms |
304 KB |
Output is correct |
43 |
Correct |
12 ms |
304 KB |
Output is correct |
44 |
Correct |
18 ms |
304 KB |
Output is correct |
45 |
Correct |
34 ms |
300 KB |
Output is correct |
46 |
Correct |
30 ms |
208 KB |
Output is correct |
47 |
Correct |
33 ms |
300 KB |
Output is correct |
48 |
Correct |
29 ms |
304 KB |
Output is correct |