이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> adds;
int dp[100001][4][4][4][4];
int ans (int pos, int a, int b, int c, int d) {
int &ret = dp[pos][a][b][c][d];
if (ret != -1) return ret;
if (pos == n) {
return ret = 0;
}
map <int, int> distinct;
if (a != 0) distinct[a]++;
if (b != 0) distinct[b]++;
distinct[adds[pos]]++;
int x = ans(pos + 1, b, adds[pos], c, d) + (int)distinct.size();
map <int, int> distinct2;
if (c != 0) distinct2[c]++;
if (d != 0) distinct2[d]++;
distinct2[adds[pos]]++;
x = max(x, ans(pos + 1, a, b, d, adds[pos]) + (int)distinct2.size());
return ret = x;
}
int main () {
memset(dp, -1, sizeof(dp));
string s;
cin >> n >> s;
for (auto i : s) {
if (i == 'M') adds.push_back(1);
else if (i == 'F') adds.push_back(2);
else adds.push_back(3);
}
cout << ans(0, 0, 0, 0, 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... |