제출 #685228

#제출 시각아이디문제언어결과실행 시간메모리
685228stevancvMiners (IOI07_miners)C++14
100 / 100
412 ms101200 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 1e5 + 2; const int inf = 1e9; int dp[N][4][4][4][4], a[N]; int F(int x, int y, int z) { int ans = 0; for (int i = 1; i <= 3; i++) { if (i == x || i == y || i == z) ans++; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == 'B') a[i] = 1; if (s[i] == 'F') a[i] = 2; if (s[i] == 'M') a[i] = 3; } for (int i = 0; i < n; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { for (int m = 0; m < 4; m++) { dp[i][j][k][l][m] = -inf; } } } } } dp[0][a[0]][0][0][0] = 1; dp[0][0][0][a[0]][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { for (int m = 0; m < 4; m++) { smax(dp[i][a[i]][k][l][m], dp[i - 1][k][j][l][m] + F(a[i], k, j)); smax(dp[i][j][k][a[i]][m], dp[i - 1][j][k][m][l] + F(a[i], m, l)); } } } } } int ans = -inf; for (int j = 1; j < 4; j++) { for (int k = 0; k < 4; k++) { for (int l = 1; l < 4; l++) { for (int m = 0; m < 4; m++) { smax(ans, dp[n - 1][j][k][l][m]); } } } } cout << ans << en; 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...