이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<complex>
#include<map>
#include<iomanip>
#include<set>
using namespace std;
/// M-1,B-2,F-3
int main(){
int n;
cin >> n;
map<char,int>mp;
string s;
cin >> s;
mp['M']=1;
mp['B']=2;
mp['F']=3;
long long table[2][4][4][4][4][n+1];
for(int i = n-1;i>=0;--i){
for(int j = 0;j<2;++j){
for(int l = 0;l<4;++l){
for(int r = 0;r<4;++r){
for(int k=0;k<4;++k){
for(int z = 0;z<4;++z){
table[j][l][r][k][z][i]=-1e18;
}
}
}
}
}
}
for(int j = 0;j<2;++j){
for(int l = 0;l<4;++l){
for(int r = 0;r<4;++r){
for(int k=0;k<4;++k){
for(int z = 0;z<4;++z){
table[j][l][r][k][z][n]=0;
}
}
}
}
}
for(int i = n-1;i>=0;--i){
for(int j = 0;j<2;++j){
for(int l = 0;l<4;++l){
for(int r = 0;r<4;++r){
for(int k=0;k<4;++k){
for(int z = 0;z<4;++z){
set<int>st;
int last11,last12,last21,last22;
if(j==0){
if(l)st.insert(l);
if(r)st.insert(r);
last12=r;
last11=mp[s[i]];
}
else{
if(k)st.insert(k);
if(z)st.insert(z);
last22=z;
last21=mp[s[i]];
}
st.insert(mp[s[i]]);
table[j][l][r][k][z][i]=st.size()+max(table[1][last11][last12][last21][last22][i+1], table[0][last11][last12][last21][last22][i+1]);
}
}
}
}
}
}
cout << max(table[0][0][0][0][0][0],table[1][0][0][0][0][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... |