Submission #738530

#TimeUsernameProblemLanguageResultExecution timeMemory
738530bobthebuilderCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
1 ms300 KiB
#include "mushrooms.h" #include<bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define pb push_back #define lowb(x) (x&(-x)) #define ALL(_x) _x.begin(),_x.end() #define pii pair<int,int> #define f first #define s second #define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end()) #define ll long long #define MNTO(x,y) x=min(x,y) #define MXTO(x,y) x=max(x,y) int count_mushrooms(int n) { const int blk=sqrt(n); if(n<=10){ int ans=1; REP1(i,n-1){ ans+=1-use_machine({0,i}); } return ans; } vector<int> v[2]; v[0].pb(0); int z=use_machine({0,1}),zz=use_machine({0,2}); if(z) v[1].pb(1); else v[0].pb(1); if(zz) v[1].pb(2); else v[0].pb(2); for(int i=3;i<2*blk-1;i+=2){ if(sz(v[0])>=2){ int k=use_machine({i,v[0][0],i+1,v[0][1]}); v[k%2].pb(i),v[k/2].pb(i+1); } else{ int k=use_machine({i,v[1][0],i+1,v[1][1]}); v[1-k%2].pb(i),v[1-k/2].pb(i+1); } } int mx=max(sz(v[0]),sz(v[1])); int ans=0; for(int i=2*blk-1;i<n;i+=mx+1){ vector<int> vv; vv.pb(i); int p=0; if(sz(v[1])==mx) p=1; REP1(j,mx){ vv.pb(v[p][j-1]); if(i+j>=n) break; vv.pb(i+j); } int k=use_machine(vv); v[(k%2)^(p)].pb(i); ans+=(p?k/2:(sz(vv)-1)/2-(k+1)/2); mx=max(sz(v[0]),sz(v[1])); } ans+=sz(v[0]); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...