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;
bool in[MAX_N];
int f[MAX_N];
int tot_in;
void pri(int n){
printf("%d in machine: ",tot_in);
for(int i=0;i<n;i++) if(in[i]) printf("%d ",i);
printf("\n");
for(int i=0;i<n;i++) printf("(%d: %d) ",i,f[i]);
printf("\n");
}
int get(int n){
int res=0;
bool in[n]={};
int prev=0;
for(int i=0;i<n;i++){
move_inside(i);
int q=press_button();
if(q>1) move_outside(i);
else{
res++;
in[i]=true;
}
if(q>prev) f[i]=q;
prev=q;
}
for(int i=0;i<n;i++) if(in[i]) move_outside(i);
return res;
}
bool check(int n, int x, int dif){
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>x) move_outside(i);
else{
in[i]=true;
tot_in++;
aux.push_back(i);
}
if(q>prev) f[i]=q;
prev=q;
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(n);
if(dif==1) return n;
memset(in,false,sizeof in);
memset(f,0,sizeof f);
tot_in=0;
int l=1,r=n/dif+1;
while(l+1<r){
int med=(l+r)/2;
if(check(n,med,dif)) 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... |