이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
const int N=1e5+5;
int dp[4][4][4][4][N];
int mp[500];
signed main(){
mp['M'-'A']=1;
mp['F'-'A']=2;
mp['B'-'A']=3;
int n;
string s;
cin>>n>>s;
int h=mp[s[0]-'A'];
for(int i=0;i<n;i++){
for(int x1=0;x1<4;x1++){
for(int y1=0;y1<4;y1++){
for(int x2=0;x2<4;x2++){
for(int y2=0;y2<4;y2++){
dp[x1][y1][x2][y2][i]=-1e9;
}
}
}
}
}
dp[0][h][0][0][0]=1;
dp[0][0][0][h][0]=1;
for(int i=1;i<n;i++){
int k=mp[s[i]-'A'];
for(int x1=0;x1<4;x1++){
for(int y1=0;y1<4;y1++){
for(int x2=0;x2<4;x2++){
for(int y2=0;y2<4;y2++){
set<int>st;
if(x1!=0)st.insert(x1);
if(y1!=0)st.insert(y1);
st.insert(k);
int h=st.size();
dp[y1][k][x2][y2][i]=max(dp[y1][k][x2][y2][i],dp[x1][y1][x2][y2][i-1]+h);
st.clear();
if(x2!=0)st.insert(x2);
if(y2!=0)st.insert(y2);
st.insert(k);
h=st.size();
dp[x1][y1][y2][k][i]=max(dp[x1][y1][y2][k][i],dp[x1][y1][x2][y2][i-1]+h);
}
}
}
}
}
int mx=0;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
for(int k=0;k<4;k++){
for(int l=0;l<4;l++){
mx=max(mx,dp[i][j][k][l][n-1]);
}
}
}
}
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... |