Submission #978152

#TimeUsernameProblemLanguageResultExecution timeMemory
978152phoenix0423Miners (IOI07_miners)C++17
84 / 100
1568 ms608 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<double, ll> pdl; typedef pair<ll, double> pld; #define fastio ios::sync_with_stdio(false), cin.tie(0) // #pragma GCC optimize("Ofast") #define pb push_back #define eb emplace_back #define f first #define s second #define int long long #define lowbit(x) x&-x const int maxn = 1e3 + 5; const double INF = 1e18; const int N = 998244353; map<char, int> mp = {{'M', 1}, {'F', 2}, {'B', 3}}; int dp[4][4][4][4], ndp[4][4][4][4]; int sol(int a, int b, int c){ set<int> st; st.insert(a), st.insert(b), st.insert(c); if(st.count(0)) st.erase(0); return st.size(); } signed main(void){ fastio; int n; cin>>n; string s; cin>>s; for(int i = 0; i <= 3; i++){ for(int j = 0; j <= 3; j++){ for(int k = 0; k <= 3; k++){ for(int l = 0; l <= 3; l++){ dp[i][j][k][l] = -INF; } } } } dp[0][0][0][0] = 0; for(auto x : s){ for(int i = 0; i <= 3; i++){ for(int j = 0; j <= 3; j++){ for(int k = 0; k <= 3; k++){ for(int l = 0; l <= 3; l++){ ndp[i][j][k][l] = -INF; } } } } for(int i = 0; i <= 3; i++){ for(int j = 0; j <= 3; j++){ for(int k = 0; k <= 3; k++){ for(int l = 0; l <= 3; l++){ ndp[j][mp[x]][k][l] = max(ndp[j][mp[x]][k][l], dp[i][j][k][l] + sol(i, j, mp[x])); ndp[i][j][l][mp[x]] = max(ndp[i][j][l][mp[x]], dp[i][j][k][l] + sol(k, l, mp[x])); } } } } swap(dp, ndp); } int ans = 0; for(int i = 0; i <= 3; i++){ for(int j = 0; j <= 3; j++){ for(int k = 0; k <= 3; k++){ for(int l = 0; l <= 3; l++){ ans = max(ans, dp[i][j][k][l]); } } } } cout<<ans<<"\n"; }
#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...