이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
inline void mx(int &u, int x) { u = max(u, x); }
int dp[4][4][4][4], cnt[4];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string str;
cin >> str;
map<char, int> mp;
mp['M'] = 1;
mp['B'] = 2;
mp['F'] = 3;
int ans = 0;
cnt[0] = 100;
for (int i = 0; i < n; i++) {
int dp1[4][4][4][4];
memset(dp1, 0, sizeof(dp1));
for (int j = 0; j <= 3; j++) {
if (cnt[j] > 0) {
cnt[j]--;
for (int l = 0; l <= 3; l++) {
if (cnt[l] > 0) {
cnt[l]--;
set<int> s;
if (j != 0) s.insert(j);
if (l != 0) s.insert(l);
s.insert(mp[str[i]]);
for (int w = 0; w <= 3; w++) {
if (cnt[w] > 0) {
cnt[w]--;
for (int z = 0; z <= 3; z++) {
if (cnt[z] > 0) {
mx(dp1[l][mp[str[i]]][w][z],
dp[j][l][w][z] + s.size());
}
}
cnt[w]++;
}
}
cnt[l]++;
}
}
cnt[j]++;
}
}
for (int w = 0; w <= 3; w++) {
if (cnt[w] > 0) {
cnt[w]--;
for (int z = 0; z <= 3; z++) {
if (cnt[z] > 0) {
cnt[z]--;
set<int> s;
if (w != 0) s.insert(w);
if (z != 0) s.insert(z);
s.insert(mp[str[i]]);
for (int j = 0; j <= 3; j++) {
if (cnt[j] > 0) {
cnt[j]--;
for (int l = 0; l <= 3; l++) {
if (cnt[l] > 0) {
mx(dp1[j][l][z][mp[str[i]]],
dp[j][l][w][z] + s.size());
}
}
cnt[j]++;
}
}
cnt[z]++;
}
}
cnt[w]++;
}
}
cnt[mp[str[i]]]++;
for (int j = 0; j <= 3; j++) {
for (int l = 0; l <= 3; l++) {
for (int w = 0; w <= 3; w++) {
for (int z = 0; z <= 3; z++) {
dp[j][l][w][z] = dp1[j][l][w][z];
mx(ans, dp[j][l][w][z]);
}
}
}
}
}
cout << ans;
}
# | 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... |