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;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, ll> pdl;
typedef pair<ll, double> pld;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
// #define int long long
#define lowbit(x) x&-x
const int maxn = 1e3 + 5;
const int INF = 1e9;
map<char, int> mp = {{'M', 1}, {'F', 2}, {'B', 3}};
int dp[4][4][4][4], ndp[4][4][4][4];
int sol(int a, int b, int c){
if(a == 0){
if(b == 0) return 1;
return 2 - (b == c);
}
return 3 - (a == c) - (b == c) - (a == b) + (a == c && b == c);
}
signed main(void){
fastio;
int n;
cin>>n;
string s;
cin>>s;
for(int i = 0; i <= 3; i++){
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
dp[i][j][k][l] = -INF;
}
}
}
}
dp[0][0][0][0] = 0;
for(auto x : s){
for(int i = 0; i <= 3; i++){
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
ndp[i][j][k][l] = -INF;
}
}
}
}
int c = mp[x];
for(int i = 0; i <= 3; i++){
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
ndp[i][j][l][c] = max(ndp[i][j][l][c], dp[i][j][k][l] + sol(k, l, c));
ndp[j][c][k][l] = max(ndp[j][c][k][l], dp[i][j][k][l] + sol(i, j, c));
}
}
}
}
swap(dp, ndp);
}
int ans = 0;
for(int i = 0; i <= 3; i++){
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
ans = max(ans, dp[i][j][k][l]);
}
}
}
}
cout<<ans<<"\n";
}
# | 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... |