이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |