제출 #248718

#제출 시각아이디문제언어결과실행 시간메모리
248718WLZMiners (IOI07_miners)C++14
100 / 100
1143 ms101088 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; map<char, int> mp = {{'M', 1}, {'B', 2}, {'F', 3}}; int dp[n + 1][4][4][4][4]; memset(dp, -1, sizeof dp); auto f = [](int a, int b, int c) { set<int> st; if (a != 0) { st.insert(a); } if (b != 0) { st.insert(b); } if (c != 0) { st.insert(c); } return (int) st.size(); }; dp[0][0][0][0][0] = 0; for (int i = 1; i <= n; i++) { for (int a = 0; a < 4; a++) { for (int b = 0; b < 4; b++) { for (int c = 0; c < 4; c++) { for (int d = 0; d < 4; d++) { if (dp[i - 1][a][b][c][d] == -1) { continue; } dp[i][b][mp[s[i - 1]]][c][d] = max(dp[i][b][mp[s[i - 1]]][c][d], dp[i - 1][a][b][c][d] + f(a, b, mp[s[i - 1]])); dp[i][a][b][d][mp[s[i - 1]]] = max(dp[i][a][b][d][mp[s[i - 1]]], dp[i - 1][a][b][c][d] + f(c, d, mp[s[i - 1]])); } } } } } int ans = 0; for (int a = 0; a < 4; a++) { for (int b = 0; b < 4; b++) { for (int c = 0; c < 4; c++) { for (int d = 0; d < 4; d++) { ans = max(ans, dp[n][a][b][c][d]); } } } } cout << ans << '\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...