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