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 prevDP[5][3][3][2], currDP[5][3][3][2];
inline int getVal(int curr, int mini, int maxi, bool tight) {
if (curr < 0 || curr >= 5) return 0;
if (maxi - mini >= 3) return 0;
return prevDP[curr][curr - mini][maxi - mini][tight];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
string g;
cin >> n >> m >> g;
#define FORALLSTATES for (int curr = 0; curr < 5; curr++) \
for (int mini = curr; curr - mini < 3; mini--) \
for (int maxi = curr; maxi - mini < 3; maxi++) \
for (bool tight : {false, true})
FORALLSTATES {
prevDP[curr][curr - mini][maxi - mini][tight] = 1;
}
for (int pos = n - 1; pos >= 0; pos--) {
FORALLSTATES {
int &res = currDP[curr][curr - mini][maxi - mini][tight];
res = getVal(curr + 1, mini, max(maxi, curr + 1), tight && g[pos] == 'L');
if (!tight || g[pos] == 'P') {
res += getVal(curr - 1, min(mini, curr - 1), maxi, tight && g[pos] == 'P');
if (res >= m) res -= m;
}
}
FORALLSTATES {
prevDP[curr][curr - mini][maxi - mini][tight] = currDP[curr][curr - mini][maxi - mini][tight];
currDP[curr][curr - mini][maxi - mini][tight] = 0;
}
}
cout << prevDP[2][0][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... |