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;
int d[2][32];
unsigned char bi[1000005], ci[1000005];
int n, m;
int ans = 1;
string S;
void add(int &x, int y){
x = (x + y) % m;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n >> m >> S;
for(int i = 1; i <= n; i++){
if(S[i-1] == 'L'){
bi[i] = bi[i-1] << 1 | 8;
}else{
bi[i] = bi[i-1] >> 1 | 2;
ci[i] = bi[i-1] << 1 | 8;
}
}
for(int i = 0; i < 32; i++) d[0][i] = 1;
if(S[n-1] == 'P' && ci[n] < 32) add(ans, 1);
for(int i = 1, w = 1; i < n; i++, w = !w){
for(int b = 0; b < 32; b++) d[w][b] = 0;
for(int b = 0; b < 32; b++){
if((b & 1) == 0){
add(d[w][b], d[!w][b >> 1 | 2]);
}
if((b & 16) == 0){
add(d[w][b], d[!w][b << 1 | 8]);
}
}
if(S[n-1-i] == 'P' && ci[n-i] < 32) add(ans, d[w][ci[n-i]]);
}
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... |