Submission #1118142

#TimeUsernameProblemLanguageResultExecution timeMemory
1118142overwatch9Miners (IOI07_miners)C++17
100 / 100
126 ms136784 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1; int dp[maxn][4][4][4][4]; bool ready[maxn][4][4][4][4]; string s; int n; int get_num(char c) { if (c == 'M') return 1; if (c == 'F') return 2; else return 3; } int get_score(int a, int b, int c) { if (a == 0) { if (b == 0) { if (c == 0) return 0; return 1; } else { if (b == c) return 1; return 2; } } else { if (a == b) { if (b == c) return 1; return 2; } else { if (a == c) { return 2; } else { if (b == c) return 2; return 3; } } } } int solve(int i, int a, int b, int c, int d) { if (i > n) return 0; if (ready[i][a][b][c][d]) return dp[i][a][b][c][d]; int ans = 0; int x = get_num(s[i]); int score1 = get_score(a, b, x); int score2 = get_score(c, d, x); ans = max({ans, solve(i+1, b, x, c, d) + score1, solve(i+1, a, b, d, x) + score2}); ready[i][a][b][c][d] = true; dp[i][a][b][c][d] = ans; return ans; } int main() { cin >> n >> s; s = "." + s; cout << solve(1, 0, 0, 0, 0) << '\n'; }
#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...