This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) x.begin(),x.end()
using ll=long long;
const ll INF=1LL<<60;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
string S;
cin>>S;
using table=array<array<array<int,2>,5>,5>;
table dp;
rep(i,5){
rep(j,5){
dp[i][j][0]=0;
dp[i][j][1]=0;
}
}
dp[2][2][1]=1;
rep(i,N){
table ndp;
rep(j,5){
rep(k,5){
ndp[j][k][0]=0;
ndp[j][k][1]=0;
}
}
rep(j,5){
rep(k,5){
dp[j][k][0]%=M;
dp[j][k][1]%=M;
if(k+1<5){
ndp[min(j+1,2)][k+1][0]+=dp[j][k][0];
if(S[i]=='P'){
ndp[min(j+1,2)][k+1][0]+=dp[j][k][1];
}
else{
ndp[min(j+1,2)][k+1][1]+=dp[j][k][1];
}
}
if(j-1>=0){
ndp[j-1][max(2,k-1)][0]+=dp[j][k][0];
if(S[i]=='P'){
ndp[j-1][max(2,k-1)][1]+=dp[j][k][1];
}
}
}
}
dp=move(ndp);
}
int ans=0;
rep(i,5){
rep(j,5){
ans+=dp[i][j][0];
ans+=dp[i][j][1];
ans%=M;
}
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |