제출 #397238

#제출 시각아이디문제언어결과실행 시간메모리
397238AugustinasJucasMiners (IOI07_miners)C++14
100 / 100
1006 ms100696 KiB
#include <bits/stdc++.h> using namespace std; int n; string a; int hsh(char a){ if(a == 'M') return 1; if(a == 'B') return 2; if(a == 'F') return 3; return 0; } const int dydis = 1e5+10; const int inf = 1e9; int dp[dydis][4][4][4][4]; int kek(int a, int b, int c){ set<int> st = {a, b, c}; return st.size() - st.count(0); } int main(){ for(int i = 0; i < dydis; i++){ for(int j = 0; j < 4; j++){ for(int h = 0; h < 4; h++){ for(int l = 0; l < 4; l++){ for(int g = 0; g < 4; g++){ dp[i][j][h][l][g] = -inf; } } } } } cin >> n >> a; dp[0][0][0][0][0] = 0; int ans = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < 4; j++){ for(int h = 0; h < 4; h++){ for(int l = 0; l < 4; l++){ for(int g = 0; g < 4; g++){ if(dp[i][j][h][l][g] < 0) continue; dp[i+1][h][hsh(a[i])][l][g] = max(dp[i+1][h][hsh(a[i])][l][g], dp[i][j][h][l][g] + kek(j, h, hsh(a[i]))); dp[i+1][j][h][g][hsh(a[i])] = max(dp[i+1][j][h][g][hsh(a[i])], dp[i][j][h][l][g] + kek(l, g, hsh(a[i]))); ans = max(ans, dp[i+1][h][hsh(a[i])][l][g]); ans = max(ans, dp[i+1][j][h][g][hsh(a[i])]); } } } } } cout << ans; 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...