이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int NN=1e5+1;
// m 1 b 2 f 3
int gv(char c){
return (c=='M'? 1:c=='B'? 2:3);
}
int cal(int i,int j,int k){
int z=(i==0)+(j==0)+(k==0);
if(z==0) {
if(i!=j&&j!=k&&k!=i) return 3;
else if(i==j&&j==k) return 1;
else return 2;
}
else if(z==2) return 1;
else{
if(j==0) swap(i,j);
return (j!=k)+1;
}
}
int arr[NN][4][4][4][4];
int n;
string s;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
memset(arr,-1,sizeof(arr));
cin>>n>>s;
arr[0][0][0][0][0]=0;
for(int i=0;i<n;i++){
for(int i1=0;i1<=3;i1++){
for(int j1=0;j1<=3;j1++){
for(int i2=0;i2<=3;i2++){
for(int j2=0;j2<=3;j2++){
if(arr[i][i1][j1][i2][j2]==-1) continue;
int t=gv(s[i]);
arr[i+1][j1][t][i2][j2]=max(arr[i+1][j1][t][i2][j2],arr[i][i1][j1][i2][j2]+cal(i1,j1,t));
arr[i+1][i1][j1][j2][t]=max(arr[i+1][i1][j1][j2][t],arr[i][i1][j1][i2][j2]+cal(i2,j2,t));
}
}
}
}
}
int mx=0;
for(int i1=0;i1<=3;i1++){
for(int j1=0;j1<=3;j1++){
for(int i2=0;i2<=3;i2++){
for(int j2=0;j2<=3;j2++){
mx=max(mx,arr[n][i1][j1][i2][j2]);
}
}
}
}
cout<<mx;
}
# | 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... |