이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define int long long
const long long inf=1e18;
const int MOD=1e9+7;
const int N=1e5+1;
int dp[N][3][3][3][3];//M=0 F1 B=2
signed main()
{
int n; cin>>n;
string s; cin>>s;
s='#'+s;
int ans=0;
for(int i=1;i<=n;i++){
int x=0;
if(s[i]=='F')x=1;
if(s[i]=='B')x=2;
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
for(int l=0;l<3;l++){
for(int u=0;u<3;u++){
int score;
set<int> a={x,j,k};
score=a.size();
dp[i][k][x][l][u]=max(dp[i][k][x][l][u],dp[i-1][j][k][l][u]+score);
a={x,l,u};
score=a.size();
dp[i][j][k][u][x]=max(dp[i][j][k][u][x],dp[i-1][j][k][l][u]+score);
ans=max({ans,dp[i][k][x][l][u],dp[i][j][k][u][x]});
}
}
}
}
}
cout<<ans-6;
}
# | 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... |