Submission #99534

#TimeUsernameProblemLanguageResultExecution timeMemory
99534figter001Linear Garden (IOI08_linear_garden)C++11
90 / 100
154 ms66560 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int nax = 1e6+5; int n,mod; string s; int dp[3][3][nax]; int calc(int idx,int a,int b){ if(a < 0)a = 0; if(b < 0)b = 0; if(a == 3)return 0; if(b == 3)return 0; if(idx == n) return 1; if(dp[a][b][idx] != -1) return dp[a][b][idx]; dp[a][b][idx] = (calc(idx+1,a+1,b-1) + calc(idx+1,a-1,b+1)) % mod; return dp[a][b][idx]; } int ans; void solve(int idx,int a,int b){ if(a < 0)a = 0; if(b < 0)b = 0; if(a == 3)return; if(b == 3)return; if(idx == n) return; if(s[idx] == 'P'){ ans = (ans + calc(idx+1,a+1,b-1)) % mod; solve(idx+1,a-1,b+1); }else{ solve(idx+1,a+1,b-1); } } int main(){ memset(dp,-1,sizeof(dp)); cin>>n>>mod>>s; solve(0,0,0); cout << (ans + 1)%mod << endl; }
#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...