이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |