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;
#define ll long long
const int MAXN = 1e5+5;
int dp[2][4][4][4][4];
const int INF = 1e9+7;
int f(int a, int b, int c) {
int s = 0;
for(int i = 1; i <= 3; ++i)
if(a == i || b == i || c == i) s++;
return s;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
memset(dp, -INF, sizeof(dp));
int n; cin >> n;
string s; cin >> s;
vector<int>a(n);
for (int i = 0; i < n; ++i) {
if (s[i] == 'M') a[i] = 1;
else if (s[i] == 'F') a[i] = 2;
else if (s[i] == 'B') a[i] = 3;
}
dp[1][0][0][0][0] = 0;
int ans = 0;
for (int i = 0; i <n; ++i) {
bool ic = i%2;
int p = a[i];
//cerr << p << " ";
for (int j = 0; j <= 3; ++j) {for (int k = 0; k <= 3; ++k) {
for (int l = 0; l <= 3; ++l) {for (int m = 0; m <= 3; ++m) {
int inc = f(p,j,k);
//if (p == 0 || j == 0 || k == 0) inc--;
dp[ic][p][j][l][m] = max(dp[ic][p][j][l][m],
inc+dp[ic^1][j][k][l][m]);
dp[ic][l][m][p][j] = max(dp[ic][l][m][p][j],
inc+dp[ic^1][l][m][j][k]);
}
}
}
}
}
for (int j = 0; j <= 3; ++j) {for (int k = 0; k <= 3; ++k) {
for (int l = 0; l <= 3; ++l) {for (int m = 0; m <= 3; ++m) {
ans = max(ans, dp[0][j][k][l][m]);
ans = max(ans, dp[1][j][k][l][m]);
}}}}
cout << ans << "\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... |