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 <bits/stdc++.h>
using namespace std;
int n;
int food[100005];
int memo[100005][4][4][4][4];
int different(int a, int b, int c)
{
if (a > b) swap(a, b);
if (b > c) swap(b, c);
if (a > b) swap(a, b);
int cnt = 1;
if (a != b) {
cnt++;
}
if (b != c) {
cnt++;
}
if (a == 0) cnt--;
return cnt;
}
int coal(int i, int X1, int X2, int Y1, int Y2)
{
if (i == n) return 0;
if (memo[i][X1][X2][Y1][Y2] == -1) {
int maximum = max(coal(i + 1, food[i], X1, Y1, Y2)
+ different(food[i], X1, X2),
coal(i + 1, X1, X2, food[i], Y1)
+ different(food[i], Y1, Y2));
memo[i][X1][X2][Y1][Y2] = maximum;
}
return memo[i][X1][X2][Y1][Y2];
}
int main()
{
memset(memo, -1, sizeof(memo));
cin >> n;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (c == 'M')
food[i] = 1;
else if (c == 'F')
food[i] = 2;
else if (c == 'B')
food[i] = 3;
}
int maximum = coal(0, 0, 0, 0, 0);
cout << maximum << '\n';
return 0;
}
# | 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... |