제출 #544786

#제출 시각아이디문제언어결과실행 시간메모리
544786sliviuMiners (IOI07_miners)C++17
100 / 100
102 ms616 KiB
#pragma GCC optimize("Ofast","unroll-loops") #include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n, ans = 0, dp[2][4][4][4][4] = {}, reset[4][4][4][4], precalc[4][4][4]; cin >> n; string s; cin >> s; 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; }; for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) for (int k = 0; k < 4; ++k) { precalc[i][j][k] = cost(i, j, k); for (int l = 0; l < 4; ++l) reset[i][j][k][l] = -10000; } 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; 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] + precalc[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] + precalc[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...