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;
const int nx=1e5+5;
int n, dp[nx][4][4][4][4], v[nx], ans;
string s;
int val(int a, int b, int c)
{
if (a==3&&b==3) return 1;
if (a==3) return 1+(b!=c);
if (a==b&&b==c) return 1;
if (a==b||b==c||a==c) return 2;
return 3;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>s;
if (n==1) return 1;
for (int i=0; i<n; i++) v[i+1]=s[i]=='B'?0:(s[i]=='F'?1:2);
for (int i=0; i<=n; i++) for (int j=0; j<4; j++) for (int k=0; k<4; k++) for (int x=0; x<4; x++) for (int y=0; y<4; y++) dp[i][j][k][x][y]=-1e9;
dp[0][3][3][3][3]=0;
for (int i=1; i<=n; i++)
{
for (int l1=0; l1<4; l1++)
{
for (int l2=0; l2<4; l2++)
{
for (int r1=0; r1<4; r1++)
{
for (int r2=0; r2<4; r2++)
{
dp[i][l1][l2][r2][v[i]]=max(dp[i][l1][l2][r2][v[i]], dp[i-1][l1][l2][r1][r2]+val(r1, r2, v[i]));
dp[i][l2][v[i]][r1][r2]=max(dp[i][l2][v[i]][r1][r2], dp[i-1][l1][l2][r1][r2]+val(l1, l2, v[i]));
ans=max({ans, dp[i][l1][l2][r2][v[i]], dp[i][l2][v[i]][r1][r2]});
}
}
}
}
}
cout<<ans;
}
# | 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... |