이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
int N, M, DP[1000001][3][3][2];
string S;
int main()
{
ios :: sync_with_stdio(0); cin.tie(0);
cin >> N >> M >> S;
DP[0][0][0][1] = 1;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
if (j + 1 < 3)
{
DP[i + 1][j + 1][max(0, k - 1)][0] = (DP[i + 1][j + 1][max(0, k - 1)][0] + DP[i][j][k][0]) % M;
if (S[i] == 'L') DP[i + 1][j + 1][max(0, k - 1)][1] = (DP[i + 1][j + 1][max(0, k - 1)][1] + DP[i][j][k][1]) % M;
else DP[i + 1][j + 1][max(0, k - 1)][0] = (DP[i + 1][j + 1][max(0, k - 1)][0] + DP[i][j][k][1]) % M;
}
if (k + 1 < 3)
{
DP[i + 1][max(0, j - 1)][k + 1][0] = (DP[i + 1][max(0, j - 1)][k + 1][0] + DP[i][j][k][0]) % M;
if (S[i] == 'P') DP[i + 1][max(0, j - 1)][k + 1][1] = (DP[i + 1][max(0, j - 1)][k + 1][1] + DP[i][j][k][1]) % M;
}
}
}
}
int ret = 0;
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++) ret = (ret + DP[N][j][k][0]) % M;
}
cout << (ret + 1) % M << "\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... |