이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int G[3][3] = {{0, 1, 2},
{3, 4, -1},
{5, -1, -1}};
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int*> dp(n+1);
for (int i = 0; i <= n; i++) {
dp[i] = new int[6];
}
dp[n][G[0][0]] = dp[n][G[1][1]] = 1;
dp[n][G[1][0]] = dp[n][G[0][1]] = 1;
dp[n][G[2][0]] = dp[n][G[0][2]] = 1;
for (int i = n-1; i >= 0; i--) {
dp[i][G[0][0]] = (dp[i+1][G[1][0]] + dp[i+1][G[0][1]]) % m;
dp[i][G[1][1]] = (dp[i+1][G[2][0]] + dp[i+1][G[0][2]]) % m;
dp[i][G[1][0]] = (dp[i+1][G[2][0]] + dp[i+1][G[0][1]]) % m;
dp[i][G[0][1]] = (dp[i+1][G[1][0]] + dp[i+1][G[0][2]]) % m;
dp[i][G[2][0]] = dp[i][G[0][2]] = dp[i+1][G[1][1]] % m;
}
int res = 1;
int low = 0, high = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'P') {
if (low > -2) res += dp[i+1][G[-(low-1)][max(0, high-1)]];
res %= m;
low = min(0, low+1);
high++;
}
else {
low--;
high = max(0, high-1);
}
}
cout << res;
}
# | 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... |