# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
627786 | peti1234 | Rarest Insects (IOI22_insects) | C++17 | 0 ms | 0 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;
//#include "insects.h"
const int c=2005;
int cnt, si;
bool v[c], fix[c];
int add(int a) {
assert(!v[a]);
v[a]=true;
si++;
move_inside(a);
return press_buttom();
}
void sub(int a) {
assert(v[a]);
v[a]=false;
si--;
move_outisde(a);
}
int min_cardinality(int N) {
for (int i=0; i<N; i++) {
if (add(i)==2) {
sub(i);
} else {
cnt++;
}
}
for (int i=0; i<N; i++) {
if (v[i]) {
fix[i]=1;
}
}
int lo=1, hi=n/cnt+1;
while (hi-lo>1) {
mid=(hi+lo)/2;
for (int i=0; i<N; i++) {
if (fix[i]) continue;
if (add(i)>mid) {
sub(i);
}
}
if (si==cnt*mid) {
lo=mid;
for (int i=0; i<N; i++) {
if (v[i]) {
fix[i]=1;
}
}
} else {
hi=mid;
for (int i=0; i<N; i++) {
if (fix[i]) continue;
if (!v[i]) fix[i]=1;
else {
sub(i);
}
}
}
}
return lo;
}
/*
int main()
{
return 0;
}
*/