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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const char key[] = {'M', 'B', 'F'};
const int N = 1e5;
int n;
int A[N];
int dp[N][4][4][4][4];
int count(int a, int b, int c) {
vector<int> k;
for (auto x : {a, b, c}) {
if (x < 3) {
k.push_back(x);
}
}
sort(k.begin(), k.end());
return unique(k.begin(), k.end()) - k.begin();
}
int f(int i, int a, int b, int x, int y) {
if (i == n) {
return 0;
}
int &res = dp[i][a][b][x][y];
if (~res) {
return res;
}
int c = A[i];
res = f(i + 1, b, c, x, y) + count(a, b, c);
res = max(res, f(i + 1, a, b, y, c) + count(x, y, c));
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; ++i) {
char c; cin >> c;
A[i] = find(key, key + 3, c) - key;
}
memset(dp, -1, sizeof(dp));
cout << f(0, 3, 3, 3, 3);
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... |