이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define taille(x) (int)x.size()
#define int long long
using namespace std;
map<char, int> conv = {
{'M', 1},
{'B', 2},
{'F', 3}
};
signed main(){
int lenChaine;
cin >> lenChaine;
string chaine;
cin >> chaine;
int dp[lenChaine + 1][4][4][4][4];
for (int ind = 0; ind <= lenChaine; ++ind)
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)
dp[ind][i][j][k][l] = -1;
dp[0][0][0][0][0] = 0;
int maxi = 0;
for (int ind = 0; ind < lenChaine; ++ind){
char cara = chaine[ind];
int M = 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){
if (dp[ind][i][j][k][l] == -1) //IMPOSSIBLE
continue;
int n = conv[cara];
chmax(M, dp[ind][i][j][k][l]);
//Mettre dans la premiere chaine
set<int> vals;
vals = {i, j, n};
vals.erase(0);
chmax(dp[ind + 1][j][n][k][l], dp[ind][i][j][k][l] + taille(vals));
vals = {k, l, n};
vals.erase(0);
chmax(dp[ind + 1][i][j][l][n], dp[ind][i][j][k][l] + taille(vals));
}
//cout << M << endl;
}
for (int ind = 0; ind <= lenChaine; ++ind)
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)
chmax(maxi, dp[ind][i][j][k][l]);
cout << maxi << endl;
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... |