이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int dp[2][4][4][4][4],ans;
int main(){
cin.tie(nullptr)->sync_with_stdio(0);
int n,st,c,idx,add,i,j,k,l;
string s;
cin>>n>>s;
for(i=0;i<4;i++)for(j=0;j<4;j++)for(k=0;k<4;k++)for(l=0;l<4;l++)dp[0][i][j][k][l]=dp[1][i][j][k][l]=-1e9;
dp[0][0][0][0][0]=0;
for(c=0;c<n;c++){
st=c%2;
idx=s[c]=='M'?1:s[c]=='B'?2:3;
for(i=0;i<4;i++)for(j=0;j<4;j++)for(k=0;k<4;k++)for(l=0;l<4;l++){
add=1;
if(i>0&&i!=idx)add++;
if(j>0&&j!=idx&&j!=i)add++;
dp[1-st][idx][i][k][l]=max(dp[1-st][idx][i][k][l],dp[st][i][j][k][l]+add);
add=1;
if(k>0&&k!=idx)add++;
if(l>0&&l!=idx&&l!=k)add++;
dp[1-st][i][j][idx][k]=max(dp[1-st][i][j][idx][k],dp[st][i][j][k][l]+add);
ans=max({ans,dp[1-st][idx][i][k][l],dp[1-st][i][j][idx][k]});
}
}
printf("%d",ans);
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... |