이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, mod;
string str;
// 'L' < 'P'
int dp[2][3][3][2];
void add(int &x, int val){
x += val;
if(x >= mod)
x-= mod;
}
int 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(0, mi- 1)][ma + 1][1], dp[i%2][mi][ma][1]);
add(dp[(i+1)%2][max(0, mi - 1)][ma + 1][0], dp[i%2][mi][ma][0]);
} else {
add(dp[(i+1)%2][max(0, mi - 1)][ma + 1][0], dp[i%2][mi][ma][0]);
add(dp[(i+1)%2][max(0, 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(0, ma - 1)][1], dp[i%2][mi][ma][1]);
add(dp[(i+1)%2][mi + 1][max(0, ma - 1)][0], dp[i%2][mi][ma][0]);
} else {
add(dp[(i+1)%2][mi + 1][max(0, 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<<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... |