Submission #630773

#TimeUsernameProblemLanguageResultExecution timeMemory
630773Spade1Miners (IOI07_miners)C++14
100 / 100
427 ms201416 KiB
#include<bits/stdc++.h> #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long #define ld long double #define st first #define nd second #define pb push_back #define INF INT_MAX using namespace std; const int N = 1e5 + 10; ll dp[N][4][4][4][4]; int f[N]; int g(vector<int> v) { int ret = 0; for (int i = 1; i <= 3; ++i) { for (auto j : v) { if (j == i) { ++ret; break; } } } return ret; } void solve() { int n; cin >> n; string s; cin >> s; for (int i = 1; i <= n; ++i) { if (s[i-1] == 'M') f[i] = 1; if (s[i-1] == 'F') f[i] = 2; if (s[i-1] == 'B') f[i] = 3; } memset(dp, -1, sizeof(dp)); dp[0][0][0][0][0] = 0; for (int i = 1; i <= n; ++i) { for (int s1 = 0; s1 < 4; ++s1) { for (int s2 = 0; s2 < 4; ++s2) { for (int s3 = 0; s3 < 4; ++s3) { for (int s4 = 0; s4 < 4; ++s4) { if (dp[i-1][s1][s2][s3][s4] == -1) continue; int l = g({s1, s2, f[i]}); dp[i][s2][f[i]][s3][s4] = max(dp[i][s2][f[i]][s3][s4], dp[i-1][s1][s2][s3][s4] + l); l = g({s3, s4, f[i]}); dp[i][s1][s2][s4][f[i]] = max(dp[i][s1][s2][s4][f[i]], dp[i-1][s1][s2][s3][s4] + l); } } } } } ll ans = 0; for (int s1 = 0; s1 < 4; ++s1) { for (int s2 = 0; s2 < 4; ++s2) { for (int s3 = 0; s3 < 4; ++s3) { for (int s4 = 0; s4 < 4; ++s4) { ans = max(ans, dp[n][s1][s2][s3][s4]); } } } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } }
#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...