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 in[2005],bad[2005];
int tot_in=0,dif;
bool check(int n, int x){
vector<int> inside,out;
for(int i=0;i<n;i++){
if(in[i] || bad[i]) continue;
move_inside(i);
if(press_button()>x) out.push_back(i);
else inside.push_back(i);
if(tot_in+(int)inside.size()==x*dif) break;
}
if(tot_in+(int)inside.size()==x*dif){
tot_in+=inside.size();
for(int i: inside) in[i]=true;
for(int i: out) move_outside(i);
return true;
}
for(int i: inside) move_outside(i);
for(int i: out){
move_outside(i);
bad[i]=true;
}
return false;
}
int min_cardinality(int n) {
memset(in,false,sizeof in);
memset(bad,false,sizeof bad);
tot_in=0;
for(int i=0;i<n;i++){
move_inside(i);
if(press_button()>1) move_outside(i);
else{
in[i]=true;
tot_in++;
}
}
dif=tot_in;
if(dif==1) return n;
int l=1,r=n/dif+1;
while(l+1<r){
int med=(l+r)/2;
if(check(n,med)) l=med;
else r=med;
}
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... |