#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:27: 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++){
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
13 ms |
208 KB |
Output is correct |
9 |
Correct |
15 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
9 ms |
208 KB |
Output is correct |
14 |
Correct |
7 ms |
208 KB |
Output is correct |
15 |
Correct |
7 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
208 KB |
Output is correct |
17 |
Correct |
10 ms |
208 KB |
Output is correct |
18 |
Correct |
9 ms |
208 KB |
Output is correct |
19 |
Correct |
14 ms |
208 KB |
Output is correct |
20 |
Correct |
18 ms |
208 KB |
Output is correct |
21 |
Correct |
25 ms |
208 KB |
Output is correct |
22 |
Correct |
20 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 |
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 |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
13 ms |
208 KB |
Output is correct |
9 |
Correct |
15 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
9 ms |
208 KB |
Output is correct |
14 |
Correct |
7 ms |
208 KB |
Output is correct |
15 |
Correct |
7 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
208 KB |
Output is correct |
17 |
Correct |
10 ms |
208 KB |
Output is correct |
18 |
Correct |
9 ms |
208 KB |
Output is correct |
19 |
Correct |
14 ms |
208 KB |
Output is correct |
20 |
Correct |
18 ms |
208 KB |
Output is correct |
21 |
Correct |
25 ms |
208 KB |
Output is correct |
22 |
Correct |
20 ms |
208 KB |
Output is correct |
23 |
Correct |
16 ms |
208 KB |
Output is correct |
24 |
Correct |
10 ms |
320 KB |
Output is correct |
25 |
Correct |
134 ms |
208 KB |
Output is correct |
26 |
Correct |
115 ms |
208 KB |
Output is correct |
27 |
Correct |
13 ms |
208 KB |
Output is correct |
28 |
Correct |
12 ms |
316 KB |
Output is correct |
29 |
Correct |
18 ms |
208 KB |
Output is correct |
30 |
Correct |
102 ms |
208 KB |
Output is correct |
31 |
Correct |
29 ms |
208 KB |
Output is correct |
32 |
Correct |
40 ms |
208 KB |
Output is correct |
33 |
Correct |
57 ms |
208 KB |
Output is correct |
34 |
Correct |
54 ms |
208 KB |
Output is correct |
35 |
Correct |
71 ms |
208 KB |
Output is correct |
36 |
Correct |
81 ms |
208 KB |
Output is correct |
37 |
Correct |
122 ms |
208 KB |
Output is correct |
38 |
Incorrect |
218 ms |
208 KB |
Too many queries. |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
29 ms |
208 KB |
Output is correct |
8 |
Correct |
13 ms |
328 KB |
Output is correct |
9 |
Incorrect |
209 ms |
208 KB |
Too many queries. |
10 |
Halted |
0 ms |
0 KB |
- |