제출 #252644

#제출 시각아이디문제언어결과실행 시간메모리
252644yuma220284Miners (IOI07_miners)C++14
100 / 100
222 ms101284 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...