This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |