Submission #304395

#TimeUsernameProblemLanguageResultExecution timeMemory
304395QAQAutoMatonCounting Mushrooms (IOI20_mushrooms)C++17
80.43 / 100
10 ms384 KiB
#include "mushrooms.h" #include<algorithm> const int B=135; int solve(int n,std::vector<int> &a){ std::vector<int> b; int st=B+B+3,ans=0; while(st<n){ int m=std::min(n-st,(int)a.size()); b.clear(); for(int i=0;i<m;++i){ b.emplace_back(st+i); b.emplace_back(a[i]); } ans+=(use_machine(b)+1)>>1; st+=m; } return ans; } int count_mushrooms(int n) { std::vector<int> xA(0),xB(0); xA.emplace_back(0); if(n<=B){ int ans=1; for(int i=1;i<n;++i){ ans+=!use_machine({0,i}); } return ans; } else{ int x=!use_machine({0,1}),y=!use_machine({0,2}); (x?xA:xB).emplace_back(1); (y?xA:xB).emplace_back(2); int s1,s2,w; if(x){s1=0,s2=1;w=0;} else if(y){s1=0;s2=2;w=0;} else{s1=1;s2=2;w=3;} if(n<=B+B+3){ for(int i=3;i<n;i+=2){ if(i+1==n){ (!use_machine({0,i})?xA:xB).emplace_back(i); } else{ int v=use_machine({s1,i,s2,i+1})^w; (v&2?xB:xA).emplace_back(i); (v&1?xB:xA).emplace_back(i+1); } } return xA.size(); } else{ for(int i=0;i<B;++i){ int v=use_machine({s1,(i<<1)+3,s2,(i<<1)+4})^w; (v&2?xB:xA).emplace_back((i<<1)+3); (v&1?xB:xA).emplace_back((i<<1)+4); } if(xA.size()>xB.size()){ return xA.size()+(n-B-B-3)-solve(n,xA); } else{ return xA.size()+solve(n,xB); } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...