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;
int x,dp[100005][16][16];
map<char,int>mp;
string s;
int f(int a,int b){
int l[4],r=0;
l[0]=0;l[1]=0;l[2]=0;l[3]=0;
l[a&3]++;l[a>>2]++;l[b]++;
for(int i=1;i<=3;i++)r+=(l[i]>0);
return r;
}
int rec(int i,int l,int r){
if(i==x)return 0;
if(~dp[i][l][r])return dp[i][l][r];
int c1=f(l,mp[s[i]]),c2=f(r,mp[s[i]]);
return dp[i][l][r]=max(rec(i+1,(l>>2)|(mp[s[i]]<<2),r)+c1,rec(i+1,l,(r>>2)|(mp[s[i]]<<2))+c2);
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
memset(dp,-1,sizeof(dp));
mp['M']=1;mp['F']=2;mp['B']=3;
cin>>x>>s;
cout<<rec(0,0,0);
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... |