Submission #1136315

#TimeUsernameProblemLanguageResultExecution timeMemory
1136315Saul0906Rarest Insects (IOI22_insects)C++20
71.42 / 100
33 ms484 KiB
#include "insects.h" #include <vector> #include <bits/stdc++.h> #define rep(a,b,c) for(ll a=b; a<c; a++) #define repr(a,b,c) for(ll a=b-1; a>c-1; a--) #define repa(a,b) for(auto a:b) #define ll long long #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define mid ((l+r)>>1) #define ppb pop_back using namespace std; using vi = vector<int>; const int N=2005; int dsu[N], sz[N]; int find(int x){ if(dsu[x]==-1) return x; return dsu[x]=find(dsu[x]); } void join(int x, int y){ x=find(x); y=find(y); if(x==y) return; dsu[x]=y; sz[y]+=sz[x]; } vi a; void solve(int l, int r, vi b){ if(l==r){ repa(e,b) join(e,a[l]); return; } rep(i,mid+1,r+1) move_outside(a[i]); vi bl, br; repa(e,b){ if(e<a[mid]){ bl.pb(e); continue; } move_inside(e); if(press_button()==2) bl.pb(e); else br.pb(e); move_outside(e); } solve(l,mid,bl); rep(i,mid+1,r+1) move_inside(a[i]); solve(mid+1,r,br); } int min_cardinality(int n) { int ans=n, mn=1, x; fill(dsu,dsu+n,-1); fill(sz,sz+n,1); vi b, c; rep(i,0,n){ move_inside(i); a.pb(i); if(press_button()==2){ move_outside(i); a.ppb(); b.pb(i); } } mn=1; while(mn*7<=n) mn++; if(a.size()>=mn){ x=a.size(); ans=1; while(true){ repa(e,a) move_outside(e); a.clear(); repa(e,b){ if(b.size()<x) continue; move_inside(e); a.pb(e); if(press_button()==2){ move_outside(e); a.ppb(); c.pb(e); } } if(a.size()<x) return ans; b.swap(c); c.clear(); ans++; } } if(a.size()>=64){ int l=1, r=n/a.size(); repa(e,a) move_outside(e); while(l<=r){ repa(e,b){ move_inside(e); c.pb(e); if(press_button()==mid){ move_outside(e); c.ppb(); } } x=mid; repa(e,a){ move_inside(e); x=min(x,press_button()); move_outside(e); } repa(e,c) move_outside(e); c.clear(); if(x==mid) l=mid+1; else r=mid-1; } return r; } solve(0,a.size()-1,b); rep(i,0,n) ans=min(ans,sz[find(i)]); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...