#include <bits/stdc++.h>
using namespace std;
#define int long long
main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
string x; cin >> x;
int dp[n+1][4][4][4][4];
for(int i = 0; i <= n; i++){
for(int y = 0; y < 4; y++){
for(int z = 0; z < 4; z++){
for(int k = 0; k < 4; k++){
for(int g = 0; g < 4; g++){
dp[i][y][z][k][g] = -1e9;
}
}
}
}
}
dp[0][0][0][0][0] = 0;
for(int i = 0; i < n; i++){
int rn = 0;
if(x[i] == 'M'){
rn = 1;
}
if(x[i] == 'B'){
rn = 2;
}
if(x[i] == 'F'){
rn = 3;
}
for(int y = 0; y < 4; y++){
for(int z = 0; z < 4; z++){
for(int k = 0; k < 4; k++){
for(int g = 0; g < 4; g++){
if(dp[i][y][z][k][g] == -1e9) continue;
// cout << y << " " << z << " " << k << " " << g << "\n";
//dp[i][y][z][k][g];
//miner 1
vector<int> j = {y, z, rn};
sort(j.begin(), j.end());
j.erase(unique(j.begin(), j.end()), j.end());
int sz = j.size();
if(j[0] == 0){
sz--;
}
dp[i+1][z][rn][k][g] = max(dp[i+1][z][rn][k][g], dp[i][y][z][k][g] + sz);
//miner 2
j = {k, g, rn};
sort(j.begin(), j.end());
j.erase(unique(j.begin(), j.end()), j.end());
sz = j.size();
if(j[0] == 0){
sz--;
}
dp[i+1][y][z][g][rn] = max(dp[i+1][y][z][g][rn], dp[i][y][z][k][g] + sz);
}
}
}
}
}
int mx = 0;
for(int y = 0; y < 4; y++){
for(int z = 0; z < 4; z++){
for(int k = 0; k < 4; k++){
for(int g = 0; g < 4; g++){
mx = max(mx, dp[n][y][z][k][g]);
}
}
}
}
cout << mx << "\n";
return 0;
}
Compilation message (stderr)
miners.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
5 | main(){
| ^~~~
# | 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... |