Submission #658615

#TimeUsernameProblemLanguageResultExecution timeMemory
658615pere_gilRarest Insects (IOI22_insects)C++17
0 / 100
38 ms288 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...