Submission #578448

#TimeUsernameProblemLanguageResultExecution timeMemory
578448Hacv16Miners (IOI07_miners)C++17
100 / 100
121 ms852 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 = 110000; const int INF = 0x3f3f3f3f; string s; int n, v[MAX], dp[2][4][4][4][4]; //optimize memory int add(int a, int b, int c){ //size of {a, b, c} int aux = 0; if(a) aux |= (1 << a); if(b) aux |= (1 << b); if(c) aux |= (1 << c); return __builtin_popcount(aux); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> s; for(int i = 0; i < n; i++){ if(s[i] == 'M') v[i] = 1; else if(s[i] == 'F') v[i] = 2; else v[i] = 3; } for(int i = n - 1; i >= 0; i--){ for(int a1 = 0; a1 < 4; a1++){ for(int a2 = 0; a2 < 4; a2++){ for(int b1 = 0; b1 < 4; b1++){ for(int b2 = 0; b2 < 4; b2++){ int aux = i % 2, m1 = add(v[i], a1, a2), m2 = add(v[i], b1, b2); int &ans = dp[aux][a1][a2][b1][b2]; if(i == n - 1){ ans = max(m1, m1); }else{ ans = max(m1 + dp[!aux][v[i]][a1][b1][b2], m2 + dp[!aux][a1][a2][v[i]][b1]); } } } } } } cout << dp[0][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...