# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
830509 | tolbi | Rarest Insects (IOI22_insects) | C++17 | 218 ms | 328 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |