이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
string s;cin>>s;
auto getid = [&](char u){
if (u == 'M')return 1;
else if (u == 'B')return 2;
return 3;
};
int dp[n][4][4][4][4];
for (int i = 0;i<n;++i){
for (int j = 0;j<4;++j){
for (int k = 0;k<4;++k){
for (int l = 0;l<4;++l){
for (int m = 0;m<4;++m){
dp[i][j][k][l][m] = -1;
}
}
}
}
}
function<int(int,int,int,int,int)>solve = [&](int u,int prev,int prev2,int prev3,int prev4){
if (u == n)return 0;
if (dp[u][prev][prev2][prev3][prev4]!=-1)return dp[u][prev][prev2][prev3][prev4];
int temp = getid(s[u]);
int cnts = 0,cnts2 = 0;
if (prev != 0)cnts++;
if (prev2 != 0 && prev2!=prev)cnts++;
if (temp!=prev && temp!=prev2)cnts++;
if (prev3 != 0)cnts2++;
if (prev4 != 0 && prev4!=prev3)cnts2++;
if (temp!=prev3 && temp!=prev4)cnts2++;
long long ans = max(solve(u + 1,prev2,temp,prev3,prev4) + cnts , solve(u + 1,prev,prev2,prev4,temp) + cnts2);
return dp[u][prev][prev2][prev3][prev4] = ans;
};
cout<<solve(0,0,0,0,0)<<'\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... |