Submission #544775

#TimeUsernameProblemLanguageResultExecution timeMemory
544775sliviuMiners (IOI07_miners)C++17
100 / 100
142 ms592 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0, dp[2][4][4][4][4] = {}, reset[4][4][4][4]; cin >> n; string s; cin >> s; 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) reset[i][j][k][l] = -1e9; memcpy(dp[1], reset, sizeof(reset)); dp[1][0][0][0][0] = 0; for (int i = 0; i < n; ++i) { int cur = s[i] == 'M' ? 1 : s[i] == 'F' ? 2 : 3; auto cost = [&](int x, int y, int z) { int cnt[4] = {}, ans = 0; ++cnt[x], ++cnt[y], ++cnt[z]; for (int i = 1; i < 4; ++i) ans += !!cnt[i]; return ans; }; memcpy(dp[i & 1], reset, sizeof(reset)); for (int fll = 0; fll < 4; ++fll) for (int fl = !!fll; fl < 4; ++fl) for (int sll = 0; sll < 4; ++sll) for (int sl = !!sll; sl < 4; ++sl) { dp[i & 1][fl][cur][sll][sl] = max(dp[i & 1][fl][cur][sll][sl], dp[(i & 1) ^ 1][fll][fl][sll][sl] + cost(fll, fl, cur)); dp[i & 1][fll][fl][sl][cur] = max(dp[i & 1][fll][fl][sl][cur], dp[(i & 1) ^ 1][fll][fl][sll][sl] + cost(sll, sl, cur)); ans = max({ans, dp[i & 1][fl][cur][sll][sl],dp[i & 1][fll][fl][sl][cur]}); } } cout << ans; }
#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...