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
int n, mod;
string str;
int dp[2][3][3][2];
void add(int &x, int val){
x += val;
if(x >= mod)
x-= mod;
}
int32_t main(){
cin >> n >> mod >> str;
dp[0][0][0][1] = 1;
for(int i = 0; i < n; i++){
char c = str[i];
for(int mi = 0; mi <= 2; mi++){
for(int ma = 0; ma <= 2; ma++){
if(ma != 2) {
if(c == 'L') {
add(dp[(i+1)%2][max(0LL, mi- 1)][ma + 1][1], dp[i%2][mi][ma][1]);
add(dp[(i+1)%2][max(0LL, mi - 1)][ma + 1][0], dp[i%2][mi][ma][0]);
} else {
add(dp[(i+1)%2][max(0LL, mi - 1)][ma + 1][0], dp[i%2][mi][ma][0]);
add(dp[(i+1)%2][max(0LL, mi - 1)][ma + 1][0], dp[i%2][mi][ma][1]);
}
}
if(mi != 2) {
if(c == 'P') {
add(dp[(i+1)%2][mi + 1][max(0LL, ma - 1)][1], dp[i%2][mi][ma][1]);
add(dp[(i+1)%2][mi + 1][max(0LL, ma - 1)][0], dp[i%2][mi][ma][0]);
} else {
add(dp[(i+1)%2][mi + 1][max(0LL, ma - 1)][0], dp[i%2][mi][ma][0]);
}
}
dp[i%2][mi][ma][0] = dp[i%2][mi][ma][1] = 0;
}
}
}
int sum = 0;
for(int mi = 0; mi <= 2; mi++){
for(int ma = 0; ma <= 2; ma++){
add(sum, dp[n%2][mi][ma][0]);
add(sum, dp[n%2][mi][ma][1]);
}
}
cout << sum << "\n";
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... |