Submission #615843

#TimeUsernameProblemLanguageResultExecution timeMemory
615843Koosha_mvCounting Mushrooms (IOI20_mushrooms)C++14
25 / 100
155 ms32612 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=20202,M=404; int n,ans,dp[N][M]; vector<int> A,B; int calc(int n,int x){ if(n<=0 || x>=M) return 0; if(dp[n][x]!=-1) return dp[n][x]; return dp[n][x]=min(calc(n-2,x+2),calc(n-(x+1)/2,x+1))+1; } int get(vector<int> vec){ if(vec.size()<=A.size()){ vector<int> res; f(i,0,int(vec.size())) res.pb(vec[i]),res.pb(A[i]); int prt=use_machine(res); if(prt&1) B.pb(vec[0]); else A.pb(vec[0]); prt=(prt+1)/2; return int(vec.size())-prt; } else{ vector<int> res; f(i,0,int(vec.size())) res.pb(vec[i]),res.pb(B[i]); int prt=use_machine(res); if(prt&1) A.pb(vec[0]); else B.pb(vec[0]); prt=(prt+1)/2; return prt; } } int count_mushrooms(int _n) { f(i,0,N) f(j,0,M) dp[i][j]=1; n=_n; A.pb(0); ans=A.size(); vector<int> vec; f(i,1,n){ vec.pb(i); if(vec.size()==2 && int(B.size())>0 && max(int(A.size()),int(B.size()))>1){ if(A.size()>=2 && B.size()>=1){ vector<int> res; res.pb(A[0]); res.pb(vec[0]); res.pb(A[1]); res.pb(B[0]); res.pb(vec[1]); int prt=use_machine(res)-1; if(prt&2){ B.pb(vec[0]); } else{ ans++; A.pb(vec[0]); } if(prt&1){ ans++; A.pb(vec[1]); } else{ B.pb(vec[1]); } } else{ vector<int> res; res.pb(B[0]); res.pb(vec[0]); res.pb(B[1]); res.pb(A[0]); res.pb(vec[1]); int prt=use_machine(res)-1; if(prt&2){ ans++; A.pb(vec[0]); } else{ B.pb(vec[0]); } if(prt&1){ B.pb(vec[1]); } else{ ans++; A.pb(vec[1]); } } vec.clear(); } else if(i==n-1 || int(vec.size())>=max(int(A.size()),int(B.size()))){ ans+=get(vec); vec.clear(); } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...