Submission #1008099

#TimeUsernameProblemLanguageResultExecution timeMemory
1008099vjudge1Miners (IOI07_miners)C++17
100 / 100
78 ms100728 KiB
#include "bits/stdc++.h" #define F first #define S second #define ll long long #define pii pair<ll,ll> const ll mxN = 3e5 + 5; const ll mod = 1e9 + 7; using namespace std; int dp[mxN][4][4][4][4]; signed main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); int n; string s = "#",s1; cin >>n>>s1; s += s1; int ans = 0; for(int i = 1;i <= n;i++){ int num = (s[i] == 'M' ? 1 : (s[i] == 'B' ? 2 : 3)); for(int a = 1;a < 4;a++){ for(int b = 1; b < 4;b++){ for(int c = 1;c < 4;c++){ for(int d = 1;d < 4;d++){ int val; if(num != a && a != b && b != num) val = 3; else if(num != a && a == b) val = 2; else if(num == a && a != b) val = 2; else if(num == b && a != b) val = 2; else if(num != a && a == b) val = 2; else val = 1; // cout<<i<<' '<<num<<' '<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<val<<'\n'; dp[i][num][a][c][d] =max(dp[i][num][a][c][d], dp[i - 1][a][b][c][d] + val); if(num != c && c != d && d != num) val = 3; else if(num != c && c == d) val = 2; else if(num == c && c != d) val = 2; else if(num != d && c == d) val = 2; else if(num == d && c != d) val = 2; else val = 1; // cout<<i<<' '<<num<<' '<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<val<<'\n'; dp[i][a][b][num][c] = max(dp[i][a][b][num][c],dp[i - 1][a][b][c][d] + val); ans = max({ans,dp[i][num][a][c][d],dp[i][a][b][num][c]}); } } } } // cout<<ans<<' '; } cout<<ans - 6; }
#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...