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>
#define fi first
#define se second
using namespace std;
const int N=1e5;
const int INF=1e9+7;
int dp[N+10][4][4][4][4];
int f(int a,int b,int c)
{
int ans=0;
bool cc[4]={0,0,0,0};
for(int i:{a,b,c})
{
if(i!=0 && !cc[i])
ans++;
cc[i]=true;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
string s;
cin>>n>>s;
for(int i=0;i<=n;i++)
{
for(int a=0;a<4;a++)
{
for(int b=0;b<4;b++)
{
for(int c=0;c<4;c++)
{
for(int d=0;d<4;d++)
{
dp[i][a][b][c][d]=-INF;
}
}
}
}
}
dp[0][0][0][0][0]=0;
for(int i=0;i<n;i++)
{
int x;
if(s[i]=='M')
x=1;
else if(s[i]=='F')
x=2;
else
x=3;
for(int a=0;a<4;a++)
{
for(int b=0;b<4;b++)
{
for(int c=0;c<4;c++)
{
for(int d=0;d<4;d++)
{
dp[i+1][a][b][d][x]=max(dp[i+1][a][b][d][x],dp[i][a][b][c][d]+f(c,d,x));
dp[i+1][b][x][c][d]=max(dp[i+1][b][x][c][d],dp[i][a][b][c][d]+f(a,b,x));
}
}
}
}
}
int ans=0;
for(int a=0;a<4;a++)
{
for(int b=0;b<4;b++)
{
for(int c=0;c<4;c++)
{
for(int d=0;d<4;d++)
{
ans=max(ans,dp[n][a][b][c][d]);
}
}
}
}
cout<<ans<<"\n";
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... |