Submission #1135178

#TimeUsernameProblemLanguageResultExecution timeMemory
1135178AMel0nMiners (IOI07_miners)C++20
100 / 100
396 ms836 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define ll long long #define endl '\n' #define FOR(N) for(int i = 0; i<N; i++) #define F first #define S second #define VI vector<int> #define PII pair<int,int> signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; string in; cin >> N; cin >> in; vector<int> S(N); FOR(N) { if (in[i] == 'M') S[i] = 1; else if (in[i] == 'B') S[i] = 2; else S[i] = 3; } vector<short> plus(4); vector<vector<vector<vector<vector<int>>>>> dp(2, vector<vector<vector<vector<int>>>>(4, vector<vector<vector<int>>>(4, vector<vector<int>>(4, vector<int>(4, 0))))); // i, m1prf1, m1prf2, m2prf1, m2prf2 for(int i = N-1; i >= 0; i--) { for(int f1 = 0; f1 < 4; f1++) { for(int f2 = 0; f2 < 4; f2++) { for(int f3 = 0; f3 < 4; f3++) { for(int f4 = 0; f4 < 4; f4++) { plus = {0,0,0,0}; plus[f1] = 1; plus[f2] = 1; plus[S[i]] = 1; int plus1 = plus[1] + plus[2] + plus[3]; plus = {0,0,0,0}; plus[f3] = 1; plus[f4] = 1; plus[S[i]] = 1; int plus2 = plus[1] + plus[2] + plus[3]; dp[i % 2][f1][f2][f3][f4] = max(dp[(i + 1) % 2][S[i]][f1][f3][f4] + plus1, dp[(i + 1) % 2][f1][f2][S[i]][f3] + plus2); //cout << i << ' ' << f1 << ' ' << f2 << ' ' << f3 << ' ' << f4 << ' ' << dp[i % 2][f1][f2][f3][f4] << endl; } } } } dp[(i+1) % 2].assign(4,vector<vector<vector<int>>>(4, vector<vector<int>>(4, vector<int>(4, 0)))); } cout << dp[0][0][0][0][0]; 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...