이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: Duarte Nobrega
* created: 28.05.2020
**/
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int dp [2][5][5][3], n, MOD;
string w;
void add (int &a, int b) {
a += b;
if (a >= MOD) a -= MOD;
}
int calc (int estado, char cur, char is) {
if (estado > 0) return estado;
if (cur < is) return 1;
if (cur > is) return 2;
return 0;
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> MOD >> w;
memset (dp, 0, sizeof(dp));
dp[0][2][2][0] = 1;
for (int i = 0; i < n; i++) {
for (int maior = 0; maior < 5; maior++) {
for (int menor = 0; menor <= maior; menor++) {
for (int estado = 0; estado < 3; estado++) {
// Place L
if (maior - 1 >= 0 && min (menor - 1, 1) >= 0) {
add (dp[(i + 1) & 1][maior - 1][min (menor - 1, 1)][calc (estado, 'L', w[i])], dp[i & 1][maior][menor][estado]);
}
// Place P
if (menor + 1 < 5 && max (maior + 1, 3) < 5) {
add(dp[(i + 1) & 1][max (maior + 1, 3)][menor + 1][calc (estado, 'P', w[i])], dp[i & 1][maior][menor][estado]);
}
}
}
}
for (int maior = 0; maior < 5; maior++) {
for (int menor = 0; menor < 5; menor++) {
for (int estado = 0; estado < 3; estado++) {
dp[i & 1][maior][menor][estado] = 0;
}
}
}
}
int res = 0;
for (int maior = 0; maior < 5; maior++) {
for (int menor = 0; menor <= maior; menor++) {
add (res, dp[n & 1][maior][menor][1]);
}
}
add(res, 1);
cout << res << '\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... |