Submission #114254

#TimeUsernameProblemLanguageResultExecution timeMemory
114254popovicirobertMiners (IOI07_miners)C++14
100 / 100
152 ms632 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long // 217 // 44 using namespace std; const int MAXN = (int) 1e5; char str[MAXN + 1]; int dp[4][4][4][4], aux[4][4][4][4]; char id[256]; int sol[4][4][4]; inline int get(int a, int b, int c) { if(sol[a][b][c] > 0) return sol[a][b][c]; vector <int> arr; if(a > 0) arr.push_back(a); if(b > 0) arr.push_back(b); if(c > 0) arr.push_back(c); sort(arr.begin(), arr.end()); arr.resize(unique(arr.begin(), arr.end()) - arr.begin()); return sol[a][b][c] = arr.size(); } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int n, i; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> str + 1; for(int a = 0; a < 4; a++) { for(int b = 0; b < 4; b++) { for(int c = 0; c < 4; c++) { for(int d = 0; d < 4; d++) { dp[a][b][c][d] = -3 * n; } } } } id['M'] = 1, id['F'] = 2, id['B'] = 3; dp[0][0][0][0] = 0; for(i = 0; i < n; i++) { for(int a = 0; a < 4; a++) { for(int b = 0; b < 4; b++) { for(int c = 0; c < 4; c++) { for(int d = 0; d < 4; d++) { aux[a][b][c][d] = -3 * n; } } } } for(int a = 0; a < 4; a++) { for(int b = 0; b < 4; b++) { for(int c = 0; c < 4; c++) { for(int d = 0; d < 4; d++) { int cur = id[str[i + 1]]; aux[b][cur][c][d] = max(aux[b][cur][c][d], dp[a][b][c][d] + get(a, b, cur)); aux[a][b][d][cur] = max(aux[a][b][d][cur], dp[a][b][c][d] + get(c, d, cur)); } } } } memcpy(dp, aux, sizeof(aux)); } int ans = 0; for(int a = 0; a < 4; a++) { for(int b = 0; b < 4; b++) { for(int c = 0; c < 4; c++) { for(int d = 0; d < 4; d++) { ans = max(ans, dp[a][b][c][d]); } } } } cout << ans; //cin.close(); //cout.close(); return 0; }

Compilation message (stderr)

miners.cpp: In function 'int main()':
miners.cpp:42:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin >> n >> str + 1;
                 ~~~~^~~
miners.cpp:71:48: warning: array subscript has type 'char' [-Wchar-subscripts]
                         int cur = id[str[i + 1]];
                                                ^
#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...