Submission #1135071

#TimeUsernameProblemLanguageResultExecution timeMemory
1135071Saul0906Rarest Insects (IOI22_insects)C++20
57.92 / 100
39 ms512 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){ move_outside(a[l]); repa(e,b) join(e,a[l]); return; } rep(i,mid+1,r+1) move_outside(a[i]); vi bl, br; repa(e,b){ 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; fill(dsu,dsu+n,-1); fill(sz,sz+n,1); vi b; rep(i,0,n){ move_inside(i); a.pb(i); if(press_button()==2){ move_outside(i); a.pop_back(); b.pb(i); } } 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...