Submission #837453

#TimeUsernameProblemLanguageResultExecution timeMemory
837453borisAngelovMiners (IOI07_miners)C++17
100 / 100
151 ms134084 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n; string s; int a[maxn]; int dp[maxn][4][4][4][4]; bool bl[maxn][4][4][4][4]; int calc(int x, int y, int z) { int result = 3; if (y == 0 || y == x) { --result; } if (z == 0 || z == x) { --result; } if (y == z && y != x && z != x && y != 0 && z != 0) { result = 2; } return result; } int f(int pos, int last1, int second1, int last2, int second2) { if (pos == n) { return 0; } if (bl[pos][last1][second1][last2][second2] == true) { return dp[pos][last1][second1][last2][second2]; } bl[pos][last1][second1][last2][second2] = true; int result = calc(a[pos], last1, second1) + f(pos + 1, a[pos], last1, last2, second2); result = max(result, calc(a[pos], last2, second2) + f(pos + 1, last1, second1, a[pos], last2)); return dp[pos][last1][second1][last2][second2] = result; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n >> s; for (int i = 0; i < n; ++i) { if (s[i] == 'M') { a[i] = 1; } if (s[i] == 'B') { a[i] = 2; } if (s[i] == 'F') { a[i] = 3; } } cout << f(0, 0, 0, 0, 0) << 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...