제출 #760106

#제출 시각아이디문제언어결과실행 시간메모리
760106BlagojMiners (IOI07_miners)C++17
100 / 100
555 ms612 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define all(x) x.begin(), x.end() inline void mx(int &u, int x) { u = max(u, x); } int dp[4][4][4][4], cnt[4]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string str; cin >> str; map<char, int> mp; mp['M'] = 1; mp['B'] = 2; mp['F'] = 3; int ans = 0; cnt[0] = 100; for (int i = 0; i < n; i++) { int dp1[4][4][4][4]; memset(dp1, 0, sizeof(dp1)); for (int j = 0; j <= 3; j++) { if (cnt[j] > 0) { cnt[j]--; for (int l = 0; l <= 3; l++) { if (cnt[l] > 0) { cnt[l]--; set<int> s; if (j != 0) s.insert(j); if (l != 0) s.insert(l); s.insert(mp[str[i]]); for (int w = 0; w <= 3; w++) { if (cnt[w] > 0) { cnt[w]--; for (int z = 0; z <= 3; z++) { if (cnt[z] > 0) { mx(dp1[l][mp[str[i]]][w][z], dp[j][l][w][z] + s.size()); } } cnt[w]++; } } cnt[l]++; } } cnt[j]++; } } for (int w = 0; w <= 3; w++) { if (cnt[w] > 0) { cnt[w]--; for (int z = 0; z <= 3; z++) { if (cnt[z] > 0) { cnt[z]--; set<int> s; if (w != 0) s.insert(w); if (z != 0) s.insert(z); s.insert(mp[str[i]]); for (int j = 0; j <= 3; j++) { if (cnt[j] > 0) { cnt[j]--; for (int l = 0; l <= 3; l++) { if (cnt[l] > 0) { mx(dp1[j][l][z][mp[str[i]]], dp[j][l][w][z] + s.size()); } } cnt[j]++; } } cnt[z]++; } } cnt[w]++; } } cnt[mp[str[i]]]++; for (int j = 0; j <= 3; j++) { for (int l = 0; l <= 3; l++) { for (int w = 0; w <= 3; w++) { for (int z = 0; z <= 3; z++) { dp[j][l][w][z] = dp1[j][l][w][z]; mx(ans, dp[j][l][w][z]); } } } } } cout << ans; }
#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...