#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define task "kbsiudthw"
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 2277;
int n, c[N], dp[2][4][4][4][4];
int get(int a, int b, int c){
int ans = (a != 3) + (b != 3) + 1;
if (a != 3 && a == b) --ans;
if (a == c) --ans;
if (b != 3 && a != c && b == c) --ans;
return ans;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n;
FOR (i, 1, n){
char ch ; cin >> ch;
c[i] = ch == 'B';
if (ch == 'F') c[i] = 2;
}
FOR (i, 0, 1) FOR (c1, 0, 3) FOR (c2, 0, 3) FOR (c3, 0, 3) FOR (c4, 0, 3) dp[i][c1][c2][c3][c4] = -1e9;
dp[0][3][3][3][3] = 0;
int cur = 0;
FOR (i, 1, n){
cur ^= 1;
FOR (c1, 0, 3) FOR (c2, 0, 3) FOR (c3, 0, 3) FOR (c4, 0, 3) dp[cur][c1][c2][c3][c4] = -1e9;
FOR (c1, 0, 3) FOR (c2, 0, (int)max(c1, 2)) FOR (c3, 0, 3) FOR (c4, 0, (int)max(c3, 2)){
dp[cur][c2][c[i]][c3][c4] = max(dp[cur][c2][c[i]][c3][c4], dp[cur^1][c1][c2][c3][c4] + get(c1, c2, c[i]));
dp[cur][c1][c2][c4][c[i]] = max(dp[cur][c1][c2][c4][c[i]], dp[cur^1][c1][c2][c3][c4] + get(c3, c4, c[i]));
}
}
int ans = 0;
FOR (c1, 0, 3) FOR (c2, 0, 3) FOR(c3, 0, 3) FOR (c4, 0, 3) ans = max(ans, dp[cur][c1][c2][c3][c4]);
cout << ans;
return 0;
}
Compilation message (stderr)
miners.cpp: In function 'int main()':
miners.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
miners.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |