이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
int INF = 1000000000;
int main() {
int N;
string S;
cin >> N >> S;
vector<int> X(N);
for (int i = 0; i < N; i++) {
X[i] = S[i] % 3;
}
static int DP[100001][4][4][4][4] = {};
for (int i = 0; i <= N; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
for (int m = 0; m < 4; m++) {
DP[i][j][k][l][m] = -INF;
}
}
}
}
}
DP[0][3][3][3][3] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
for (int m = 0; m < 4; m++) {
int A, B, C, D[3] = {};
A = j, B = k, C = X[i], D[0] = D[1] = D[2] = 0;
if (A == 3) A = X[i];
if (B == 3) B = X[i];
D[A] = D[B] = D[C] = 1;
DP[i + 1][k][X[i]][l][m] = max(DP[i + 1][k][X[i]][l][m], DP[i][j][k][l][m] + D[0] + D[1] + D[2]);
A = l, B = m, C = X[i], D[0] = D[1] = D[2] = 0;
if (A == 3) A = X[i];
if (B == 3) B = X[i];
D[A] = D[B] = D[C] = 1;
DP[i + 1][j][k][m][X[i]] = max(DP[i + 1][j][k][m][X[i]], DP[i][j][k][l][m] + D[0] + D[1] + D[2]);
}
}
}
}
}
int ANS = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
ANS = max(ANS, DP[N][i][j][k][l]);
}
}
}
}
cout << ANS << endl;
}
# | 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... |