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 int ll;
const int maxn=1e5 + 10;
int di[4]={1,-1,0,0};
int dj[4]={0,0,-1,1};
int n;
string s;
int dp[maxn][4][4][4][4];
int f(int idx,int a,int b,int c,int d)
{
if(idx==n)
{
return 0;
}
if(dp[idx][a][b][c][d]!=-1)return dp[idx][a][b][c][d];
int rez=0;
int x=0;
if(s[idx]=='M')
{
x=1;
}
else if(s[idx]=='F')
{
x=2;
}
else
{
x=3;
}
set<int>se1;
se1.insert(a);
se1.insert(b);
se1.insert(x);
set<int>se2;
se2.insert(c);
se2.insert(d);
se2.insert(x);
int num=se1.size();
if(a==0 || b==0)
{
num--;
}
rez=max(rez, f(idx+1,b,x,c,d)+num);
num=se2.size();
if(c==0 || d==0)
{
num--;
}
rez=max(rez, f(idx+1,a,b,d,x)+num);
return dp[idx][a][b][c][d]=rez;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin>>n>>s;
memset(dp,-1,sizeof dp);
cout<<f(0,0,0,0,0)<<endl;
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... |