| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1365477 | Iwanttobreakfree | Miners (IOI07_miners) | C++20 | 32 ms | 632 KiB |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, ans = 0;
cin >> n;
string s;
cin >> s;
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 = s[i];
int cur = 0;
if (c == 'M') cur = 1;
else if (c == 'F') cur = 2;
else cur = 3;
int sumA = 1, sumB = 1;
vector<int> idxA(4), idxB(4);
idxA[0] = idxB[0] = -10;
idxA[cur] = idxB[cur] = 1;
for (int j1 = 0; j1 < 4; ++j1) {
idxA[j1]++;
sumA += (idxA[j1] == 1);
for (int j2 = 0; j2 < 4; ++j2) {
idxA[j2]++;
sumA += (idxA[j2] == 1);
for (int j3 = 0; j3 < 4; ++j3) {
idxB[j3]++;
sumB += (idxB[j3] == 1);
for (int j4 = 0; j4 < 4; ++j4) {
idxB[j4]++;
sumB += (idxB[j4] == 1);
dp[cur][j1][j3][j4][1] = max(dp[j1][j2][j3][j4][0] + sumA, dp[cur][j1][j3][j4][1]);
dp[j1][j2][cur][j3][1] = max(dp[j1][j2][j3][j4][0] + sumB, dp[j1][j2][cur][j3][1]);
idxB[j4]--;
sumB -= (idxB[j4] == 0);
}
idxB[j3]--;
sumB -= (idxB[j3] == 0);
}
idxA[j2]--;
sumA -= (idxA[j2] == 0);
}
idxA[j1]--;
sumA -= (idxA[j1] == 0);
}
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];
}
}
}
}
}
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) {
ans = max(ans, dp[j1][j2][j3][j4][0]);
}
}
}
}
cout << ans << '\n';
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
