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 n,a[100001],i,dp[100001][4][4][4][4];
string s;
int val(vector<int> v){
set<int> s;
for(int x:v){
if(x) s.insert(x);
}
return s.size();
}
int rec(int idx,int a1,int a2,int b1,int b2){
if(idx==n) return 0;
int &res=dp[idx][a1][a2][b1][b2];
if(res!=-1) return res;
int m1,m2;
m1=val({a1,a2,a[idx]});
m2=val({b1,b2,a[idx]});
return res=max(rec(idx+1,a[idx],a1,b1,b2)+m1,rec(idx+1,a1,a2,a[idx],b1)+m2);
}
int main(){
memset(dp,-1,sizeof dp);
cin >> n >> s;
for(i=0;i<n;i++){
if(s[i]=='M') a[i]=1;
if(s[i]=='B') a[i]=2;
if(s[i]=='F') a[i]=3;
}
cout << rec(0,0,0,0,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... |