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 "insects.h"
#include <bits/stdc++.h>
using namespace std;
bool a[2005], b[2005];
vector<int> v;
int min_cardinality(int n)
{
srand(time(0));
for (int i=0; i<n; i++)
v.push_back(i);
random_shuffle(v.begin(), v.end());
int d=0;
for (int i:v)
{
move_inside(i);
b[i]=1;
d++;
if (press_button()>1)
{
move_outside(i);
b[i]=0;
d--;
}
}
for (int i:v)
{
if (b[i])
{
move_outside(i);
a[i]=1;
}
}
int l=0, r=(n-d)/d, ans=1;
while (l<r)
{
random_shuffle(v.begin(), v.end());
int k=(l+r+1)/2, cnt=0;
for (int i:v)
{
if (a[i])
continue;
move_inside(i);
b[i]=1;
cnt++;
if (press_button()>k)
{
move_outside(i);
b[i]=0;
cnt--;
}
if (cnt==k*d)
break;
}
if (cnt==k*d)
{
for (int i:v)
{
if (a[i])
continue;
if (b[i])
{
move_outside(i);
a[i]=1;
}
}
ans+=k;
r-=k;
}
else
{
for (int i:v)
{
if (a[i])
continue;
if (b[i])
{
move_outside(i);
b[i]=0;
}
else
a[i]=1;
}
r=k-1;
}
}
return ans+l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |