제출 #1151029

#제출 시각아이디문제언어결과실행 시간메모리
1151029btninhMiners (IOI07_miners)C++20
35 / 100
54 ms64584 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 100005; const int mod = 1e9 + 7; int n, a[N], dp[N][3][3][3][3]; int cost(int a, int b, int c){ int cnt = 0; if (a == 0 || b == 0 || c == 0) ++cnt; if (a == 1 || b == 1 || c == 1) ++cnt; if (a == 2 || b == 2 || c == 2) ++cnt; return cnt; } signed main(){ //freopen("test.inp","r",stdin); //freopen("test.out","w",stdout); ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; ++i){ char c; cin >> c; if (c == 'M') a[i] = 0; if (c == 'F') a[i] = 1; if (c == 'B') a[i] = 2; } for(int i = 0; i <= n; ++i) for(int j1 = 0; j1 < 3; ++j1) for(int j2 = 0; j2 < 3; ++j2) for(int k1 = 0; k1 < 3; ++k1) for(int k2 = 0; k2 < 3; ++k2) dp[i][j1][j2][k1][k2] = -1e18; dp[1][a[1]][a[1]][a[1]][a[1]] = 1; dp[2][a[2]][a[1]][a[1]][a[1]] = dp[2][a[1]][a[1]][a[2]][a[1]]= 1 + (a[1] != a[2]); for(int i = 3; i <= n; ++i){ for(int j1 = 0; j1 < 3; ++j1){ for(int j2 = 0; j2 < 3; ++j2){ for(int k1 = 0; k1 < 3; ++k1){ for(int k2 = 0; k2 < 3; ++k2){ int cst1 = cost(a[i], j1, j2), cst2 = cost(a[i], k1, k2); dp[i][a[i]][j1][k1][k2] = max(dp[i][a[i]][j1][k1][k2], dp[i-1][j1][j2][k1][k2] + cst1); dp[i][j1][j2][a[i]][k1] = max(dp[i][j1][j2][a[i]][k1], dp[i-1][j1][j2][k1][k2] + cst2); } } } } } int ans = 0; for(int j1 = 0; j1 < 3; ++j1) for(int j2 = 0; j2 < 3; ++j2) for(int k1 = 0; k1 < 3; ++k1) for(int k2 = 0; k2 < 3; ++k2) ans = max({ans, dp[n][a[n]][j1][k1][k2], dp[n][j1][j2][a[n]][k1]}); cout << ans; }
#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...