이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n;
string a;
int hsh(char a){
if(a == 'M') return 1;
if(a == 'B') return 2;
if(a == 'F') return 3;
return 0;
}
const int dydis = 1e5+10;
const int inf = 1e9;
int dp[dydis][4][4][4][4];
int kek(int a, int b, int c){
set<int> st = {a, b, c};
return st.size() - st.count(0);
}
int main(){
for(int i = 0; i < dydis; i++){
for(int j = 0; j < 4; j++){
for(int h = 0; h < 4; h++){
for(int l = 0; l < 4; l++){
for(int g = 0; g < 4; g++){
dp[i][j][h][l][g] = -inf;
}
}
}
}
}
cin >> n >> a;
dp[0][0][0][0][0] = 0;
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < 4; j++){
for(int h = 0; h < 4; h++){
for(int l = 0; l < 4; l++){
for(int g = 0; g < 4; g++){
if(dp[i][j][h][l][g] < 0) continue;
dp[i+1][h][hsh(a[i])][l][g] = max(dp[i+1][h][hsh(a[i])][l][g], dp[i][j][h][l][g] + kek(j, h, hsh(a[i])));
dp[i+1][j][h][g][hsh(a[i])] = max(dp[i+1][j][h][g][hsh(a[i])], dp[i][j][h][l][g] + kek(l, g, hsh(a[i])));
ans = max(ans, dp[i+1][h][hsh(a[i])][l][g]);
ans = max(ans, dp[i+1][j][h][g][hsh(a[i])]); }
}
}
}
}
cout << ans;
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... |