# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
292126 | Kastanda | Miners (IOI07_miners) | C++11 | 177 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// M
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, dp[4][4][4][4], dpt[4][4][4][4];
char A[N];
int main()
{
scanf("%d%s", &n, A);
for (int i = 0; i < n; i ++)
{
if (A[i] == 'M') A[i] = 1;
if (A[i] == 'B') A[i] = 2;
if (A[i] == 'F') A[i] = 3;
}
auto Get = [](int a, int b, int c){
int C[4] = {0, 0, 0, 0};
C[a] = C[b] = C[c] = 1;
return C[1] + C[2] + C[3];
};
memset(dp, -63, sizeof(dp));
dp[0][0][0][0] = 0;
for (int i = 0; i < n; i ++)
{
memset(dpt, -63, sizeof(dpt));
for (int a = 0; a < 4; a ++)
for (int b = 0; b < 4; b ++)
for (int c = 0; c < 4; c ++)
for (int d = 0; d < 4; d ++)
{
dpt[a][b][d][A[i]] = max(dpt[a][b][d][A[i]], dp[a][b][c][d] + Get(c, d, A[i]));
dpt[b][A[i]][c][d] = max(dpt[b][A[i]][c][d], dp[a][b][c][d] + Get(a, b, A[i]));
}
memcpy(dp, dpt, sizeof(dp));
}
int Mx = 0;
for (int a = 0; a < 4; a ++)
for (int b = 0; b < 4; b ++)
for (int c = 0; c < 4; c ++)
for (int d = 0; d < 4; d ++)
Mx = max(Mx, dp[a][b][c][d]);
return !printf("%d\n", Mx);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |