Submission #384445

#TimeUsernameProblemLanguageResultExecution timeMemory
384445ak2006Miners (IOI07_miners)C++14
100 / 100
845 ms876 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; const ll mod = 1e9 + 7,inf = 1e18; #define pb push_back #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int dp[2][4][4][4][4]; int main() { fast; int n; cin>>n; vi a(n); for (int i = 0;i<n;i++){ char x; cin>>x; if (x == 'M')a[i] = 0; else if (x == 'F')a[i] = 1; else a[i] = 2; } for (int i = n - 1;i>=0;i--){ for (int a1 = 3;a1>=0;a1--){ for (int a2 = 3;a2>=0;a2--){ for (int b1 = 3;b1>=0;b1--){ for (int b2 = 3;b2>=0;b2--){ int bon1 = 0,bon2 = 0; vi f(4); f[a[i]]++,f[a1]++,f[a2]++; bon1 = (f[0] >= 1 ? 1 : 0) + (f[1] >= 1 ? 1 : 0) + (f[2] >= 1 ? 1 : 0); f[0] = 0,f[1] = 0,f[2] = 0; f[a[i]]++,f[b1]++,f[b2]++; bon2 = (f[0] >= 1 ? 1 : 0) + (f[1] >= 1 ? 1 : 0) + (f[2] >= 1 ? 1 : 0); if (i == n - 1)dp[i%2][a1][a2][b1][b2] = max(bon1,bon2); else dp[i%2][a1][a2][b1][b2] = max(bon1 + dp[(i + 1)%2][a[i]][a1][b1][b2],bon2 + dp[(i + 1)%2][a1][a2][a[i]][b1]); } } } } } cout<<dp[0][3][3][3][3]; 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...