이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define F first
#define S second
#define ll long long
#define pii pair<ll,ll>
const ll mxN = 3e5 + 5;
const ll mod = 1e9 + 7;
using namespace std;
int dp[mxN][4][4][4][4];
signed main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int n;
string s = "#",s1;
cin >>n>>s1;
s += s1;
int ans = 0;
for(int i = 1;i <= n;i++){
int num = (s[i] == 'M' ? 1 : (s[i] == 'B' ? 2 : 3));
for(int a = 1;a < 4;a++){
for(int b = 1; b < 4;b++){
for(int c = 1;c < 4;c++){
for(int d = 1;d < 4;d++){
if(dp[i - 1][a][b][c][d] == -1) continue;
int val;
if(num != a && a != b && a && b) val = 3;
else if(num != a && (a == b || !b)&& a) val = 2;
else if((num == a || !a) && a != b && b) val = 2;
else val = 1;
// cout<<i<<' '<<num<<' '<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<val<<'\n';
dp[i][num][a][c][d] =max(dp[i][num][a][c][d], dp[i - 1][a][b][c][d] + val);
if(num != c && c != d && c && d) val = 3;
else if(num != c && (c == d || !d) && c) val = 2;
else if((num == c || !c) && c != d && d) val = 2;
else val = 1;
// cout<<i<<' '<<num<<' '<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<val<<'\n';
dp[i][a][b][num][c] = max(dp[i][a][b][num][c],dp[i - 1][a][b][c][d] + val);
ans = max({ans,dp[i][num][a][c][d],dp[i][a][b][num][c]});
}
}
}
}
// cout<<ans<<' ';
}
cout<<ans - 6;
}
# | 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... |