이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int prev_dp[5][5][3][2];
int curr_dp[5][5][3][2];
int n, m;
string g;
int getVal(int curr_diff, int min_diff, int max_diff, bool tight) {
if (curr_diff < 0 || curr_diff >= 5) return 0;
if (max_diff - min_diff >= 3) return 0;
return prev_dp[curr_diff][min_diff][max_diff - min_diff][tight];
}
void compute(int pos, int curr_diff, int min_diff, int max_diff, bool tight) {
int &res = curr_dp[curr_diff][min_diff][max_diff - min_diff][tight];
res = getVal(curr_diff + 1, min_diff, max(max_diff, curr_diff + 1), tight && g[pos] == 'L');
if (!tight || g[pos] == 'P') {
res += getVal(curr_diff - 1, min(min_diff, curr_diff - 1), max_diff, tight && g[pos] == 'P');
if (res >= m) res -= m;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> g;
for (int curr_diff = 0; curr_diff < 5; curr_diff++) {
for (int min_diff = 0; min_diff < 5; min_diff++) {
for (int max_diff = min_diff; max_diff - min_diff < 3; max_diff++) {
for (bool tight : {false, true}) {
prev_dp[curr_diff][min_diff][max_diff - min_diff][tight] = 1;
}
}
}
}
for (int pos = n - 1; pos >= 0; pos--) {
for (int curr_diff = 0; curr_diff < 5; curr_diff++) {
for (int min_diff = 0; min_diff < 5; min_diff++) {
for (int max_diff = min_diff; max_diff - min_diff < 3; max_diff++) {
for (bool tight : {false, true}) {
compute(pos, curr_diff, min_diff, max_diff, tight);
}
}
}
}
for (int curr_diff = 0; curr_diff < 5; curr_diff++) {
for (int min_diff = 0; min_diff < 5; min_diff++) {
for (int max_diff = min_diff; max_diff - min_diff < 3; max_diff++) {
for (bool tight : {false, true}) {
prev_dp[curr_diff][min_diff][max_diff - min_diff][tight] = curr_dp[curr_diff][min_diff][max_diff - min_diff][tight];
curr_dp[curr_diff][min_diff][max_diff - min_diff][tight] = 0;
}
}
}
}
}
cout << prev_dp[2][2][0][1] << '\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... |