This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* Magician: tht2005
* Spawned: 2021.10.17 14:12:11
**/
// dp(i, j, k, l) : pos i, j steps to min, k steps to max, l = different from prefix
#include <bits/stdc++.h>
using namespace std;
int n, md, res, dp[3][3][2], aux[3][3][2];
string s;
void add(int& a, int b)
{
if((a += b) >= md) a -= md;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> md >> s;
dp[0][0][0] = 1;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < 3; ++j) {
for(int k = 0; k < 3; ++k) {
for(int l = 0; l < 2; ++l) {
aux[j][k][l] = dp[j][k][l];
dp[j][k][l] = 0;
}
}
}
for(int j = 0; j < 3; ++j) {
for(int k = 0; k < 3; ++k) {
for(int l = 0; l < 2; ++l) {
int ft = aux[j][k][l];
if(ft > 0) {
if(j < 2) add(dp[j + 1][max(0, k - 1)][(int)(l || s[i] == 'P')], ft);
if((l || s[i] == 'P') && k < 2) add(dp[max(0, j - 1)][k + 1][l], ft);
}
}
}
}
}
res = 0;
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 3; ++j) {
for(int k = 0; k < 2; ++k) {
add(res, dp[i][j][k]);
}
}
}
cout << res;
return 0;
}
# | 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... |