/*
Author : detective conan
Problem : 2003
*/
#include <bits/stdc++.h>
#define int long long
#define FFOR(i, s, t) for (int i = s; i <= t; ++i)
#define FBOR(i, s, t) for (int i = s; i >= t; --i)
#define DB(n, s) cout << n << s
#define ANS(n, s) DB(n, s)
#define HAVE_TESTCASE false
#define mod (int)(1e9 + 7)
#define sum(a, b) (a + b) % mod
#define mul(a, b) ((a % mod) * (b % mod)) % mod
#define N (int)(1e5 + 100)
#define conan cin.tie(nullptr)->sync_with_stdio(false)
#define pb emplace_back
#define cal(a, b, c) (a == 1 || b == 1 || c == 1) + (a == 2 || b == 2 || c == 2) + (a == 3 || b == 3 || c == 3)
using namespace std;
int n, a[N], dp[2][4][4][4][4], ans;
void solve(){
cin >> n;
FFOR(i, 1, n){
char c; cin >> c;
if(c == 'M') a[i] = 1;
if(c == 'B') a[i] = 2;
if(c == 'F') a[i] = 3;
}
dp[1][a[1]][0][0][0] = dp[1][0][0][a[1]][0] = 1;
FFOR(it, 2, n){
int c = it&1, p = c ^ 1, x = a[it];
FFOR(i, 0, 3) FFOR(j, 0, 3) FFOR(k, 0, 3) FFOR(l, 0, 3) if(dp[p][i][j][k][l]) dp[c][x][i][k][l] = max(dp[c][x][i][k][l], dp[p][i][j][k][l] + cal(x, i, j)), dp[c][i][j][x][k] = max(dp[c][i][j][x][k], dp[p][i][j][k][l] + cal(x, k, l));
}
FFOR(i, 0, 3) FFOR(j, 0, 3) FFOR(k, 0, 3) FFOR(l, 0, 3) ans = max(ans, dp[n&1][i][j][k][l]);
ANS(ans, '\n');
}
int32_t main() {
conan;
int t = 1;
if (HAVE_TESTCASE) cin >> t;
while (t--) solve();
}
# | 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... |