Submission #896727

#TimeUsernameProblemLanguageResultExecution timeMemory
896727LCJLYLinear Garden (IOI08_linear_garden)C++14
0 / 100
26 ms65536 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long typedef pair<int,int>pii; int n,m; string s,s2; int memo[1000005][5][5][2][2]; int dp(int index, int k, int k2, bool bound, int last){ if(index==n) return 1; if(memo[index][k+2][k2+2][bound][last]!=-1) return memo[index][k+2][k2+2][bound][last]; int ans=0; if(bound){ int target=s[index]-'0'; int next=max(0,k)+1; int next2=k2-1; if(abs(next)<=2&&abs(next2)<=2){ ans=(ans+dp(index+1,next,next2,(target==1),1))%m; } if(target==2){ next=k; next--; next2=max(k2,0)+1; if(abs(next)<=2&&abs(next2)<=2) ans=(ans+dp(index+1,next,next2,(target==2),2))%m; } } else{ int next=max(0,k)+1; int next2=k2-1; if(abs(next)<=2&&abs(next2)<=2) ans=(ans+dp(index+1,next,next2,0,1))%m; next=k; next2=max(k2,0)+1; next--; if(abs(next)<=2&&abs(next2)<=2) ans=(ans+dp(index+1,next,next2,0,2))%m; } return memo[index][k+2][k2+2][bound][last]=(ans)%m; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); memset(memo,-1,sizeof(memo)); cin >>n >> m >> s2; for(int x=0;x<n;x++){ if(s2[x]=='L')s.push_back('1'); else s.push_back('2'); } int hold=(dp(0,0,0,1,0))%m; cout << hold; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...