#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
struct dsu{
vector<ll> p;
dsu(ll n):p(n,-1){}
ll g(ll i){
return p[i]<0?i:p[i] = g(p[i]);
}
bool m(ll a, ll b){
a = g(a),b = g(b);
if (a==b) return false;
if(p[a]>p[b]) swap(a,b);
p[a] += p[b];
p[b] = a;
return true;
}
};
int min_cardinality(int n) {
mt19937_64 mt(random_device{}());
vector<ll> a(n);
iota(a.begin(),a.end(),0);
dsu d(n);
ll run = 1;
while(run){
run = 0;
shuffle(a.begin(),a.end(),mt);
vector<ll> v;
for(ll i : a) if(d.p[i]<0) v.push_back(i);
ll l = 0;
for(ll i = 0;i<v.size();i++){
move_inside(v[i]);
if (i>0&&press_button()>1){
do{
move_outside(v[l++]);
}while(press_button()>1);
d.m(v[l-1],v[i]);
run = 1;
}
}
while(l<v.size())move_outside(v[l++]);
}
ll ans = -n;
for(ll i : d.p) if(i<0)ans = max(ans,i);
return -ans;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:32:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(ll i = 0;i<v.size();i++){
| ~^~~~~~~~~
insects.cpp:42:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | while(l<v.size())move_outside(v[l++]);
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
8 ms |
344 KB |
Output is correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
4 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
7 ms |
344 KB |
Output is correct |
19 |
Correct |
20 ms |
344 KB |
Output is correct |
20 |
Correct |
12 ms |
344 KB |
Output is correct |
21 |
Correct |
11 ms |
344 KB |
Output is correct |
22 |
Correct |
31 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
8 ms |
344 KB |
Output is correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
4 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
7 ms |
344 KB |
Output is correct |
19 |
Correct |
20 ms |
344 KB |
Output is correct |
20 |
Correct |
12 ms |
344 KB |
Output is correct |
21 |
Correct |
11 ms |
344 KB |
Output is correct |
22 |
Correct |
31 ms |
344 KB |
Output is correct |
23 |
Correct |
7 ms |
344 KB |
Output is correct |
24 |
Correct |
5 ms |
344 KB |
Output is correct |
25 |
Correct |
70 ms |
344 KB |
Output is correct |
26 |
Correct |
46 ms |
344 KB |
Output is correct |
27 |
Correct |
9 ms |
344 KB |
Output is correct |
28 |
Correct |
14 ms |
344 KB |
Output is correct |
29 |
Correct |
18 ms |
344 KB |
Output is correct |
30 |
Correct |
44 ms |
344 KB |
Output is correct |
31 |
Correct |
23 ms |
344 KB |
Output is correct |
32 |
Correct |
24 ms |
344 KB |
Output is correct |
33 |
Correct |
26 ms |
344 KB |
Output is correct |
34 |
Correct |
34 ms |
344 KB |
Output is correct |
35 |
Correct |
35 ms |
344 KB |
Output is correct |
36 |
Correct |
40 ms |
344 KB |
Output is correct |
37 |
Correct |
73 ms |
344 KB |
Output is correct |
38 |
Correct |
100 ms |
344 KB |
Output is correct |
39 |
Correct |
127 ms |
344 KB |
Output is correct |
40 |
Correct |
169 ms |
340 KB |
Output is correct |
41 |
Correct |
165 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
19 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
440 KB |
Output is correct |
9 |
Partially correct |
145 ms |
344 KB |
Output is partially correct |
10 |
Partially correct |
119 ms |
344 KB |
Output is partially correct |
11 |
Correct |
27 ms |
344 KB |
Output is correct |
12 |
Correct |
40 ms |
448 KB |
Output is correct |
13 |
Partially correct |
34 ms |
340 KB |
Output is partially correct |
14 |
Partially correct |
145 ms |
444 KB |
Output is partially correct |
15 |
Partially correct |
50 ms |
344 KB |
Output is partially correct |
16 |
Partially correct |
62 ms |
340 KB |
Output is partially correct |
17 |
Partially correct |
72 ms |
596 KB |
Output is partially correct |
18 |
Partially correct |
61 ms |
344 KB |
Output is partially correct |
19 |
Partially correct |
77 ms |
344 KB |
Output is partially correct |
20 |
Partially correct |
88 ms |
344 KB |
Output is partially correct |
21 |
Partially correct |
170 ms |
596 KB |
Output is partially correct |
22 |
Partially correct |
175 ms |
596 KB |
Output is partially correct |
23 |
Incorrect |
231 ms |
464 KB |
Too many queries. |
24 |
Halted |
0 ms |
0 KB |
- |