Submission #728519

#TimeUsernameProblemLanguageResultExecution timeMemory
728519groguRarest Insects (IOI22_insects)C++17
47.50 / 100
253 ms628 KiB
#include "insects.h" #define dbg(x) cerr<<#x<<": "<<x<<endl #include <bits/stdc++.h> #define ll int #define pll pair<ll,ll> using namespace std; #define maxn 2005 ll n; set<ll> s; ll uniq = 0; ll F[maxn]; bool ok[maxn]; ll val[maxn]; ll cur = 0; void add(ll i){ if(s.find(i)!=s.end()) return; move_inside(i); s.insert(i); } void del(ll i){ if(s.find(i)==s.end()){ cerr<<"out"<<endl; return; } move_outside(i); s.erase(i); } ll get(){return press_button();} void klir(){ while(s.size()) del(*s.begin()); } ll f(ll x){ if(F[x]!=-1) return F[x]; if(cur>x) klir(),cur = 0; for(ll i = 0;i<n;i++){ add(i); cur = get(); if(cur>x) del(i); else val[i] = cur; } return F[x] = s.size(); } ll min_cardinality(ll N) { for(ll i = 0;i<maxn;i++) F[i] = -1; n = N; for(ll i = 0;i<n;i++) ok[i] = 1; uniq = f(1); //dbg(uniq); ll l = 1, r = n,mid,rez = n; while(l<=r){ mid = (l+r)/2; for(ll i = 0;i<n;i++) val[i] = -1; if(f(mid)==uniq*mid) l = mid+1,rez = mid; else{ for(ll i = 0;i<n;i++){ if(s.find(i)!=s.end()&&val[i]>=mid) ok[i] = 0; } r = mid-1; } } return rez; } /** 6 5 8 9 5 9 9 **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...