Submission #946904

#TimeUsernameProblemLanguageResultExecution timeMemory
946904yellowtoadMiners (IOI07_miners)C++17
100 / 100
213 ms200788 KiB
#include <iostream> using namespace std; long long n, dp[100010][4][4][4][4], num, maxx; char ch; int main() { cin >> n; for (int i = 0; i <= n; i++) for (int a = 0; a <= 3; a++) for (int b = 0; b <= 3; b++) for (int c = 0; c <= 3; c++) for (int d = 0; d <= 3; d++) dp[i][a][b][c][d] = -1e18; dp[0][0][0][0][0] = 0; for (int i = 1; i <= n; i++) { cin >> ch; if (ch == 'M') num = 1; else if (ch == 'B') num = 2; else num = 3; for (int a = 0; a <= 3; a++) { for (int b = 0; b <= 3; b++) { for (int c = 0; c <= 3; c++) { for (int d = 0; d <= 3; d++) { if ((a == 0) && (b == 0)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+1); else if ((a == 0) && (b == num)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+1); else if ((a == 0) && (b != num)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+2); else if ((a == b) && (b == num)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+1); else if ((a != b) && (b != num) && (a != num)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+3); else dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+2); if ((c == 0) && (d == 0)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+1); else if ((c == 0) && (d == num)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+1); else if ((c == 0) && (d != num)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+2); else if ((c == d) && (d == num)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+1); else if ((c != d) && (d != num) && (c != num)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+3); else dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+2); } } } } } for (int a = 0; a <= 3; a++) for (int b = 0; b <= 3; b++) for (int c = 0; c <= 3; c++) for (int d = 0; d <= 3; d++) maxx = max(maxx,dp[n][a][b][c][d]); cout << maxx << 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...