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>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int MAX = 1e5 + 10;
int N;
int arr[MAX];
string s;
int f[MAX][8][4][8][4];
void solve(){
cin >> N >> s;
for(int i = 1; i <= N; i++){
if(s[i - 1] == 'M') arr[i] = 0;
if(s[i - 1] == 'F') arr[i] = 1;
if(s[i - 1] == 'B') arr[i] = 2;
}
memset(f, -0x3f, sizeof f);
f[0][0][3][0][3] = 0;
for(int i = 0; i < N; i++){
for(int a = 0; a < 8; a++) for(int b = 0; b < 4; b++){
for(int x = 0; x < 8; x++) for(int y = 0; y < 4; y++) if(f[i][a][b][x][y] >= 0){
maximize(f[i + 1][(b == 3 ? 0 : MASK(b)) | MASK(arr[i + 1])][arr[i + 1]][x][y], f[i][a][b][x][y] + __builtin_popcount(a | MASK(arr[i + 1])));
maximize(f[i + 1][a][b][(y == 3 ? 0 : MASK(y)) | MASK(arr[i + 1])][arr[i + 1]], f[i][a][b][x][y] + __builtin_popcount(x | MASK(arr[i + 1])));
}
}
}
int ans = 0;
for(int a = 0; a < 8; a++) for(int b = 0; b < 4; b++){
for(int x = 0; x < 8; x++) for(int y = 0; y < 4; y++) if(f[N][a][b][x][y] >= 0){
maximize(ans, f[N][a][b][x][y]);
}
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("capsomayman.inp","r",stdin);
// freopen("capsomayman.out","w",stdout);
int t = 1;
// cin >> t;
while(t--){
solve();
}
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... |