Submission #578071

#TimeUsernameProblemLanguageResultExecution timeMemory
578071Hacv16Miners (IOI07_miners)C++17
0 / 100
294 ms524288 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second typedef long long ll; const int MAX = 2e5 + 15; const int INF = 0x3f3f3f3f; string s; ll n, v[MAX], memo[MAX][5][5][5][5]; ll add(ll a, ll b, ll c){ //how many are produced with this triplet? unordered_set<int> aux; if(a) aux.insert(a); if(b) aux.insert(b); if(c) aux.insert(c); return aux.size(); } ll f(char c){ if(c == 'M') return 1; else if(c == 'F') return 2; return 3; } ll dp(ll i, ll a1, ll a2, ll b1, ll b2){ if(memo[i][a1][a2][b1][b2] != -1) return memo[i][a1][a2][b1][b2]; if(i == n + 1) return 0; ll cur = - INF; cur = max(cur, dp(i + 1, v[i], a1, b1, b2) + add(v[i], a1, a2)); cur = max(cur, dp(i + 1, a1, a2, v[i], b1) + add(v[i], b1, b2)); return memo[i][a1][a2][b1][b2] = cur; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); memset(memo, -1, sizeof(memo)); cin >> n >> s; for(int i = 0; i < n; i++) v[i + 1] = f(s[i]); cout << dp(1, 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...