# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384000 | iulia13 | Miners (IOI07_miners) | C++14 | 94 ms | 492 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.
#include <iostream>
#include <algorithm>
using namespace std;
const int nmax = 1e5 + 5;
const int mskmax = 16;
const int b = 4;
char s[nmax];
int dp[2][mskmax][mskmax];
///M = 1, F = 2, B = 3
///nmc = 0
int cod[30];
int value[80];
void maxim(int &a, int b)
{
a = max(a, b);
}
int v[3];
int main()
{
int n, i, j;
cin >> n;
cin >> s + 1;
cod['M' - 'A'] = 1;
cod['F' - 'A'] = 2;
cod['B' - 'A'] = 3;
for (i = 0; i < mskmax * b; i++)
{
if (i == 63)
i = 63;
v[0] = i % b;
v[1] = (i / b) % b;
v[2] = i / (b * b);
sort (v, v + 3);
if (v[2] == 0)
continue;
if (v[1] == 0)
{
value[i] = 1;
continue;
}
if (v[0] == 0)
{
if (v[1] == v[2])
value[i] = 1;
else
value[i] = 2;
continue;
}
if (!v[0])
continue;
if (v[0] == v[2])
value[i] = 1;
else
if (v[0] != v[1] && v[2] != v[1])
value[i] = 3;
else
value[i] = 2;
}
int val = cod[s[1] - 'A'];
for (i = 0; i <= 1; i++)
for (int msk1 = 0; msk1 < mskmax; msk1++)
for (int msk2 = 0; msk2 < mskmax; msk2++)
dp[i][msk1][msk2] = -2e9;
dp[0][0][0] = 0;
int ans = 0;
for (i = 1; i <= n; i++)
{
for (int msk1 = 0; msk1 < mskmax; msk1++)
for (int msk2 = 0; msk2 < mskmax; msk2++)
dp[i % 2][msk1][msk2] = -2e9;
for (int msk1 = 0; msk1 < mskmax; msk1++)
for (int msk2 = 0; msk2 < mskmax; msk2++)
{
int val = cod[s[i] - 'A'];
int msk11 = (msk1 % b) * b + val;
int msk22 = (msk2 % b) * b + val;
///bag in primul
maxim(dp[i % 2][msk11][msk2], dp[1 - i % 2][msk1][msk2] + value[msk1 + b * b * val]);
maxim(dp[i % 2][msk1][msk22], dp[1 - i % 2][msk1][msk2] + value[msk2 + b * b * val]);
if (i == n)
{
maxim(ans, dp[i % 2][msk11][msk2]);
maxim(ans, dp[i % 2][msk1][msk22]);
}
}
}
cout << ans;
return 0;
}
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... |