Submission #413743

#TimeUsernameProblemLanguageResultExecution timeMemory
413743ruadhanMiners (IOI07_miners)C++17
100 / 100
241 ms200980 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int MX = 1e5 + 5; ll dp[MX][4][4][4][4]; int N; int score(int a, int b, int c) { int ret = 0; if (a == 1 || b == 1 || c == 1) ret++; if (a == 2 || b == 2 || c == 2) ret++; if (a == 3 || b == 3 || c == 3) ret++; return ret; } int main() { cin >> N; for (int i = 0; i <= N; i++) for (int a = 0; a < 4; a++) for (int b = 0; b < 4; b++) for (int c = 0; c < 4; c++) for (int d = 0; d < 4; d++) dp[i][a][b][c][d] = -1; dp[0][0][0][0][0] = 0; string S; cin >> S; for (int i = 0; i < N; i++) { int x = 0; if (S[i] == 'B') x = 1; if (S[i] == 'F') x = 2; if (S[i] == 'M') x = 3; for (int a = 0; a < 4; a++) for (int b = 0; b < 4; b++) for (int c = 0; c < 4; c++) for (int d = 0; d < 4; d++) { if (dp[i][a][b][c][d] == -1) continue; dp[i + 1][a][b][d][x] = max(dp[i + 1][a][b][d][x], dp[i][a][b][c][d] + score(c, d, x)); dp[i + 1][b][x][c][d] = max(dp[i + 1][b][x][c][d], dp[i][a][b][c][d] + score(a, b, x)); } } ll ans = 0; for (int a = 0; a < 4; a++) for (int b = 0; b < 4; b++) for (int c = 0; c < 4; c++) for (int d = 0; d < 4; d++) ans = max(ans, dp[N][a][b][c][d]); cout << ans << '\n'; return 0; }
#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...