Submission #577933

#TimeUsernameProblemLanguageResultExecution timeMemory
577933MohamedFaresNebiliMiners (IOI07_miners)C++14
100 / 100
429 ms1020 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; #define ff first #define ss second #define pb push_back #define all(x) x.begin(), x.end() int n, arr[2*100005]; string s; map<char, int> m; ll dp[2][4][4][4][4]; int solve(int i, int j, int k) { int res = 0; for(int l = 1; l <= 3; l++) if(l == i || l == j || l == k) res++; return res; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s; m['M'] = 1, m['B'] = 2, m['F'] = 3; for(int l = 0; l < n; l++) arr[l + 1] = m[s[l]]; int a = 0, b = 1; for(int l = n; l > 0; l--) { swap(a, b); for(int u0 = 0; u0 < 4; u0++) for(int u = 0; u < 4; u++) for(int v0 = 0; v0 < 4; v0++) for(int v = 0; v < 4; v++) dp[a][u0][u][v0][v] = max(dp[b][u][arr[l]][v0][v] + solve(u0, u, arr[l]), dp[b][u0][u][v][arr[l]] + solve(v0, v, arr[l])); } cout << dp[a][0][0][0][0] << "\n"; 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...