Submission #253698

#TimeUsernameProblemLanguageResultExecution timeMemory
253698MounirMiners (IOI07_miners)C++14
100 / 100
1175 ms201032 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...