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;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
const int N = 100002;
int dp[N][4][4][4][4];
int n;
string s;
int rec(int i , int a , int b , int c ,int d){
if(i == n)return 0;
if(dp[i][a][b][c][d]!=-1)return dp[i][a][b][c][d];
int cur;
if(s[i] == 'M')cur = 0;
else if(s[i] == 'F')cur = 1;
else cur = 2;
int cnt = 0;
if(a == 1 || b == 1 || cur == 1)cnt++;
if(a == 0 || b == 0 || cur == 0)cnt++;
if(a == 2 || b == 2 || cur == 2)cnt++;
int res = cnt + rec(i + 1 , b , cur , c , d);
cnt = 0;
if(c == 1 || d == 1 || cur == 1)cnt++;
if(c == 0 || d == 0 || cur == 0)cnt++;
if(c == 2 || d == 2 || cur == 2)cnt++;
res = max(res , cnt + rec(i + 1 , a , b , d , cur));
return dp[i][a][b][c][d] = res;
}
void solve(){
cin >> n;
cin >> s;
memset(dp,-1,sizeof dp);
cout << rec(0,3,3,3,3) << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;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... |