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;
const int nx=2e3+5;
int p, cnt, sz, in[nx], t[nx], s[nx];
int min_cardinality(int N) {
cin.tie(NULL)->sync_with_stdio(false);
for (int i=0; i<N; i++)
{
move_inside(i);
if (press_button()==1) cnt++, in[i]=1, s[i]=1;
else move_outside(i);
}
if (cnt==1) return N;
if (cnt==N) return 1;
int l=1, r=N/cnt;
sz=cnt;
while (l<r)
{
int md=(l+r+1)/2;
for (int i=0; i<N; i++)
{
if (s[i]||t[i]) continue;
move_inside(i);
if (press_button()>md) move_outside(i);
else sz++, in[i]=1;
if (sz==cnt*md) break;
}
if (sz==cnt*md)
{
l=md;
for (int i=0; i<N; i++) if (in[i]) s[i]=1;
}
else
{
r=md-1;
for (int i=0; i<N; i++) if (!in[i]) t[i]=1;
for (int i=0; i<N; i++) if (in[i]&&!s[i]) in[i]=0, move_outside(i), sz--;
}
}
return 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... |