이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
#define ss second
#define ff first
#define ext exit(0)
using namespace std;
int n,i,j,p,t,k,a,dp[100001][4][4][4][4],ans;
string s;
inline int sol(int o, int oo , int ooo){
if(o==oo && oo==ooo) return 1;
else if(o==oo || o==ooo || ooo==oo) return 2;
else return 3;
}
int main (){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>s;
for(i=0;i<n;i++){
if(s[i]=='M') a=0;
else if(s[i]=='B') a=1;
else a=2;
for(j=0;j<3;j++){
for(k=0;k<3;k++){
for(t=0;t<3;t++){
for(p=0;p<3;p++){
dp[i+1][k][a][t][p]=max(dp[i+1][k][a][t][p],dp[i][j][k][t][p]+sol(k,a,j));
dp[i+1][j][k][p][a]=max(dp[i+1][j][k][p][a],dp[i][j][k][t][p]+sol(t,a,p));
}
}
}
}
}
for(j=0;j<3;j++){
for(k=0;k<3;k++){
for(t=0;t<3;t++){
for(p=0;p<3;p++) ans=max(ans,dp[n][j][k][t][p]-6);
}
}
}
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... |