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 int long long
signed main(){
int n,m,r=0; cin >> n >> m; string s; cin >> s;
vector dp(5,vector(5,vector<int>(5))); auto res = dp; for (int i(0);i < 5;++i) dp[i][i][i] = 1;
int t = 2; for (char a:s) t += (a=='L'?1:-1);
for (int i(n-1);i > -1;--i){
t -= (s[i]=='L'?1:-1);
if (s[i]=='P'&&t+1<5) for (int k(0);k < 5;++k) for (int j(0);j < 5;++j) (r += dp[t+1][k][j])%=m;
for (int u(0);u < 5;++u){
for (int k(0);k < 5;++k) for (int j(0);j < 5;++j) res[u][k][j] = 0;
if (u!=4) for (int k(0);k < 5;++k) for (int j(k);j < 4;++j) (res[u][min(k+1,u+1)][max(j+1,u+1)] += dp[u][k][j])%=m;
if (u!=0) for (int k(1);k < 5;++k) for (int j(k);j < 5;++j) (res[u][min(k-1,u-1)][max(j-1,u-1)] += dp[u][k][j])%=m;
}
swap(dp,res);
}
cout << r << endl;
}
# | 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... |