이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MN=1e5+2;
int N,dp[2][4][4][4][4],a[MN];
string s;
inline int calc(char x,char y,char z) {
return (x==1||y==1||z==1)+(x==2||y==2||z==2)+(x==3||y==3||z==3);
}
int main() {
ios::sync_with_stdio(0);cin.tie(0);
cin>>N>>s;
for(int i=0;i<N;++i) {
if(s[i]=='B') a[i+1]=1;
if(s[i]=='F') a[i+1]=2;
if(s[i]=='M') a[i+1]=3;
}
for(int i=0;i<2;++i) for(int j=0;j<4;++j) for(int k=0;k<4;++k) for(int l=0;l<4;++l) for(int m=0;m<4;++m) dp[i][j][k][l][m]=INT_MIN;
dp[0][0][0][0][0]=0;
int ans=0;
for(int i=1;i<=N;++i)
for(int j=0;j<4;++j)
for(int k=0;k<4;++k)
for(int l=0;l<4;++l)
for(int m=0;m<4;++m) {
dp[i&1][k][a[i]][l][m]=max(dp[i&1][k][a[i]][l][m],dp[(i-1)&1][j][k][l][m]+calc(a[i],j,k));
dp[i&1][j][k][m][a[i]]=max(dp[i&1][j][k][m][a[i]],dp[(i-1)&1][j][k][l][m]+calc(a[i],l,m));
ans=max({ans,dp[i&1][j][a[i]][l][m],dp[i&1][j][k][l][a[i]]});
}
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... |