Submission #535119

#TimeUsernameProblemLanguageResultExecution timeMemory
535119kebineMiners (IOI07_miners)C++17
100 / 100
129 ms600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long ul; typedef double dbl; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef map<ll, ll> mll; typedef pair<string, ll> psl; typedef map<string, ll> msl; typedef vector<int> vi; typedef vector<ll> vll; typedef deque<ll> deq; typedef priority_queue<ll, vector<ll>, greater<ll>> pqm; typedef priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> dij; typedef priority_queue<ll> pq; typedef string str; const ll mod=1e9+9; const ll maxn=2e5+1; ll gcd(ll a, ll b) { return a==0 ? b : gcd(a, b%a); } ll lcm(ll a, ll b) { ll ans=a*b; ans=ans/(gcd(a, b)); return ans; } #define ihacoy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define dh << endl; #define co cout << #define udh cout << endl; #define spa << " "; #define ci cin >> #define fi first #define se second #define sp << " " << #define tes while(t--) #define pb push_back #define pf push_front #define pob pop_back() #define pof pop_front() #define gre greater<ll>() #define sip return 0 #define ub upper_bound #define lb lower_bound #define bs binary_search int n, nxt, now, ans; str s; int main() { ihacoy ci n >> s; int dp[2][4][4][4][4]; memset(dp, -1, sizeof dp); dp[0][0][0][0][0]=0; for(int i=0; i<n; i++) { for(int j=0; j<=3; j++) { for(int k=0; k<=3; k++) { for(int l=0; l<=3; l++) { for(int m=0; m<=3; m++) { if(dp[i%2][j][k][l][m]<0) continue; if(s[i]=='M') nxt=1; else if(s[i]=='B') nxt=2; else nxt=3; now=1; if(j && j!=nxt) now++; if(k && k!=nxt && k!=j) now++; dp[(i+1)%2][nxt][j][l][m]=max(dp[(i+1)%2][nxt][j][l][m], dp[i%2][j][k][l][m]+now); now=1; if(l && l!=nxt) now++; if(m && m!=nxt && m!=l) now++; dp[(i+1)%2][j][k][nxt][l]=max(dp[(i+1)%2][j][k][nxt][l], dp[i%2][j][k][l][m]+now); } } } } } 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[n%2][i][j][k][l]); } } } } co 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...