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