이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n,x[100010];
int dp[2][4][4][4][4];
string s;
int cnt(int a,int b,int c){
int tmp=0;
if (a==1||b==1||c==1)tmp++;
if (a==2||b==2||c==2)tmp++;
if (a==3||b==3||c==3)tmp++;
return tmp;
}
int main(){
cin>>n>>s;
for (int i=0;i<n;i++){
if (s[i]=='M')x[i]=1;
else if (s[i]=='F')x[i]=2;
else x[i]=3;
}
int now=1;
memset(dp,-1,sizeof(dp));
dp[0][0][0][0][0]=0;
for (int k=0;k<n;k++){
memset(dp[now],-1,sizeof(dp[now]));
for (int a=0;a<=3;a++)
for (int b=0;b<=3;b++)
for (int c=0;c<=3;c++)
for (int d=0;d<=3;d++)
if(dp[1-now][a][b][c][d]!=-1){
dp[now][x[k]][a][c][d]=max(dp[now][x[k]][a][c][d],dp[1-now][a][b][c][d]+cnt(x[k],a,b));//LEFT
dp[now][a][b][x[k]][c]=max(dp[now][a][b][x[k]][c],dp[1-now][a][b][c][d]+cnt(x[k],c,d));
}
now=1-now;
}
int ans=-1;
for (int a=0;a<=3;a++)
for (int b=0;b<=3;b++)
for (int c=0;c<=3;c++)
for (int d=0;d<=3;d++)ans=max(ans,dp[1-now][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... |