#include <bits/stdc++.h>
using namespace std;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
#include "insects.h"
int min_cardinality(int n) {
vector<int> par(n);
function<int(int)> find = [&](int node)->int{
if (par[node]==node) return node;
return par[node]=find(par[node]);
};
vector<int> hueh(n);
iota(hueh.begin(), hueh.end(), 0);
for (int i = n-1; i >= 0; i--){
swap(hueh[i],hueh[ayahya()%(i+1)]);
}
vector<int> sz(n,1);
iota(par.begin(), par.end(), 0);
vector<int> crr;
function<int()> findx;
findx = [&]()->int{
for (int i = 0; i < crr.size(); i++){
move_outside(crr[i]);
if (press_button()==1){
for (int j=0;j<=i;j++){
move_inside(crr[j]);
}
return i;
}
}
return 23;
};
for (int kk = 0; kk < n; kk++){
int i = hueh[kk];
move_inside(i);
if (press_button()>1){
int pos = crr[findx()];
sz[find(pos)]+=sz[find(i)];
sz[find(i)]=0;
par[i]=find(pos);
move_outside(i);
}
else crr.push_back(i);
}
int ans = n;
for (int i = 0; i < n; i++){
if (find(i)!=i) continue;
ans=min(ans,sz[i]);
}
return ans;
}
Compilation message
insects.cpp: In lambda function:
insects.cpp:21:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < crr.size(); i++){
| ~~^~~~~~~~~~~~
# |
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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
4 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
10 ms |
208 KB |
Output is correct |
9 |
Correct |
10 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
208 KB |
Output is correct |
11 |
Correct |
4 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
208 KB |
Output is correct |
13 |
Correct |
12 ms |
208 KB |
Output is correct |
14 |
Correct |
9 ms |
208 KB |
Output is correct |
15 |
Correct |
10 ms |
208 KB |
Output is correct |
16 |
Correct |
13 ms |
208 KB |
Output is correct |
17 |
Correct |
12 ms |
208 KB |
Output is correct |
18 |
Correct |
8 ms |
208 KB |
Output is correct |
19 |
Correct |
9 ms |
208 KB |
Output is correct |
20 |
Correct |
26 ms |
208 KB |
Output is correct |
21 |
Correct |
24 ms |
208 KB |
Output is correct |
22 |
Correct |
33 ms |
208 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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
4 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
10 ms |
208 KB |
Output is correct |
9 |
Correct |
10 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
208 KB |
Output is correct |
11 |
Correct |
4 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
208 KB |
Output is correct |
13 |
Correct |
12 ms |
208 KB |
Output is correct |
14 |
Correct |
9 ms |
208 KB |
Output is correct |
15 |
Correct |
10 ms |
208 KB |
Output is correct |
16 |
Correct |
13 ms |
208 KB |
Output is correct |
17 |
Correct |
12 ms |
208 KB |
Output is correct |
18 |
Correct |
8 ms |
208 KB |
Output is correct |
19 |
Correct |
9 ms |
208 KB |
Output is correct |
20 |
Correct |
26 ms |
208 KB |
Output is correct |
21 |
Correct |
24 ms |
208 KB |
Output is correct |
22 |
Correct |
33 ms |
208 KB |
Output is correct |
23 |
Correct |
15 ms |
208 KB |
Output is correct |
24 |
Correct |
6 ms |
208 KB |
Output is correct |
25 |
Correct |
87 ms |
208 KB |
Output is correct |
26 |
Correct |
161 ms |
208 KB |
Output is correct |
27 |
Correct |
9 ms |
208 KB |
Output is correct |
28 |
Correct |
17 ms |
208 KB |
Output is correct |
29 |
Correct |
29 ms |
208 KB |
Output is correct |
30 |
Correct |
117 ms |
208 KB |
Output is correct |
31 |
Correct |
23 ms |
208 KB |
Output is correct |
32 |
Correct |
57 ms |
208 KB |
Output is correct |
33 |
Correct |
43 ms |
208 KB |
Output is correct |
34 |
Correct |
50 ms |
208 KB |
Output is correct |
35 |
Correct |
53 ms |
208 KB |
Output is correct |
36 |
Correct |
105 ms |
208 KB |
Output is correct |
37 |
Correct |
200 ms |
208 KB |
Output is correct |
38 |
Incorrect |
307 ms |
208 KB |
Too many queries. |
39 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
31 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
336 KB |
Output is correct |
9 |
Incorrect |
272 ms |
208 KB |
Too many queries. |
10 |
Halted |
0 ms |
0 KB |
- |