제출 #550769

#제출 시각아이디문제언어결과실행 시간메모리
550769JomnoiMiners (IOI07_miners)C++17
100 / 100
373 ms892 KiB
#include <bits/stdc++.h> #define DEBUG false using namespace std; const int MAX_N = 1e5 + 10; char S[MAX_N]; int A[MAX_N]; int dp[2][4][4][4][4]; int cal(const int &x, const int &y, const int &z) { int res = 0; for(int i = 1; i <= 3; i++) { if(x == i or y == i or z == i) { res++; } } return res; } int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N >> (S + 1); for(int i = 1; i <= N; i++) { if(S[i] == 'M') { A[i] = 1; } else if(S[i] == 'B') { A[i] = 2; } else if(S[i] == 'F') { A[i] = 3; } } for(int i = N; i >= 1; i--) { for(int i1 = 0; i1 <= 3; i1++) { for(int i2 = 0; i2 <= 3; i2++) { for(int j1 = 0; j1 <= 3; j1++) { for(int j2 = 0; j2 <= 3; j2++) { dp[1][i1][i2][j1][j2] = max(dp[0][A[i]][i1][j1][j2] + cal(A[i], i1, i2), dp[0][i1][i2][A[i]][j1] + cal(A[i], j1, j2)); } } } } for(int i1 = 0; i1 <= 3; i1++) { for(int i2 = 0; i2 <= 3; i2++) { for(int j1 = 0; j1 <= 3; j1++) { for(int j2 = 0; j2 <= 3; j2++) { dp[0][i1][i2][j1][j2] = dp[1][i1][i2][j1][j2]; } } } } } 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...