| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1365465 | Iwanttobreakfree | Miners (IOI07_miners) | C11 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
int dp[4][4][4][4][2];
for (int j1 = 0; j1 < 4; ++j1) {
for (int j2 = 0; j2 < 4; ++j2) {
for (int j3 = 0; j3 < 4; ++j3) {
for (int j4 = 0; j4 < 4; ++j4) {
dp[j1][j2][j3][j4][0] = dp[j1][j2][j3][j4][1] = -1e9;
}
}
}
}
dp[0][0][0][0][0] = dp[0][0][0][0][1] = 0;
for (int i = 0; i < n; ++i) {
char c;
cin >> c;
int cur = 0;
if (c == 'M') cur = 1;
else if (c == 'F') cur = 2;
else cur = 3;
for (int j1 = 0; j1 < 4; ++j1) {
for (int j2 = 0; j2 < 4; ++j2) {
for (int j3 = 0; j3 < 4; ++j3) {
for (int j4 = 0; j4 < 4; ++j4) {
set<int> s1;
s1.insert(cur);
s1.insert(j1);
s1.insert(j2);
s1.erase(0);
dp[cur][j1][j3][j4][1] = max(dp[j1][j2][j3][j4][0] + (int)s1.size(), dp[cur][j1][j3][j4][1]);
s1.clear();
s1.insert(cur);
s1.insert(j3);
s1.insert(j4);
s1.erase(0);
dp[j1][j2][cur][j3][1] = max(dp[j1][j2][j3][j4][0] + (int)s1.size(), dp[j1][j2][cur][j3][1]);
}
}
}
}
for (int j1 = 0; j1 < 4; ++j1) {
for (int j2 = 0; j2 < 4; ++j2) {
for (int j3 = 0; j3 < 4; ++j3) {
for (int j4 = 0; j4 < 4; ++j4) {
dp[j1][j2][j3][j4][0] = dp[j1][j2][j3][j4][1];
ans = max(ans, dp[j1][j2][j3][j4][0]);
}
}
}
}
}
cout << ans << '\n';
}