Submission #582429

#TimeUsernameProblemLanguageResultExecution timeMemory
582429snasibov05Miners (IOI07_miners)C++14
100 / 100
932 ms125760 KiB
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 5; int dp[mx][4][4][4][4]; bool v[mx][4][4][4][4]; map<char, int> mp; int cnt(int l1, int l2, char c){ set<int> st; if (l1 != 0) st.insert(l1); if (l2 != 0) st.insert(l2); st.insert(mp[c]); return st.size(); } int main() { int n; cin >> n; string str; cin >> str; mp['B'] = 1, mp['F'] = 2, mp['M'] = 3; v[0][0][0][0][0] = true; for (int i = 0; i < n; ++i){ for (int l11 = 0; l11 < 4; ++l11){ for (int l12 = 0; l12 < 4; ++l12){ for (int l21 = 0; l21 < 4; ++l21){ for (int l22 = 0; l22 < 4; ++l22){ if (!v[i][l11][l12][l21][l22]) continue; dp[i+1][l12][mp[str[i]]][l21][l22] = max(dp[i+1][l12][mp[str[i]]][l21][l22], dp[i][l11][l12][l21][l22] + cnt(l11, l12, str[i])); v[i+1][l12][mp[str[i]]][l21][l22] = true; dp[i+1][l11][l12][l22][mp[str[i]]] = max(dp[i+1][l11][l12][l22][mp[str[i]]], dp[i][l11][l12][l21][l22] + cnt(l21, l22, str[i])); v[i+1][l11][l12][l22][mp[str[i]]] = true; } } } } } int MX = 0; for (int l11 = 0; l11 < 4; ++l11){ for (int l12 = 0; l12 < 4; ++l12){ for (int l21 = 0; l21 < 4; ++l21){ for (int l22 = 0; l22 < 4; ++l22){ if (!v[n][l11][l12][l21][l22]) continue; MX = max(MX, dp[n][l11][l12][l21][l22]); } } } } cout << MX << "\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...