제출 #114515

#제출 시각아이디문제언어결과실행 시간메모리
114515zubecMiners (IOI07_miners)C++14
91 / 100
176 ms476 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int n; int dp[2][4][4][4][4]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin >> n; int tt = 0; for (int t = 0; t < 2; t++){ for (int i = 0; i < 4; i++){ for (int j = 0; j < 4; j++){ for (int ii = 0; ii < 4; ii++){ for (int jj = 0; jj < 4; jj++){ dp[t][i][j][ii][jj] = -1e9; } } } } } dp[0][0][0][0][0] = 0; while(n--){ char c; cin >> c; int cur = 0; if (c == 'M') cur = 1; else if (c == 'B') cur = 2; else cur = 3; for (int i = 0; i < 4; i++){ for (int j = 0; j < 4; j++){ for (int ii = 0; ii < 4; ii++){ for (int jj = 0; jj < 4; jj++){ dp[tt^1][i][j][ii][jj] = -1e9; } } } } for (int i = 0; i < 4; i++){ for (int j = 0; j < 4; j++){ for (int ii = 0; ii < 4; ii++){ for (int jj = 0; jj < 4; jj++){ { int a = i, b = j, c = cur; if (a > b) swap(a, b); if (b > c) swap(b, c); if (a > b) swap(a, b); int kol = 1; if (a != b && a != 0) ++kol; if (b != c && b != 0) ++kol; dp[tt^1][j][cur][ii][jj] = max(dp[tt^1][j][cur][ii][jj], dp[tt][i][j][ii][jj]+kol); } { int a = ii, b = jj, c = cur; if (a > b) swap(a, b); if (b > c) swap(b, c); if (a > b) swap(a, b); int kol = 1; if (a != b && a != 0) ++kol; if (b != c && b != 0) ++kol; dp[tt^1][i][j][jj][cur] = max(dp[tt^1][i][j][jj][cur], dp[tt][i][j][ii][jj]+kol); } } } } } tt^=1; } int ans = 0; for (int i = 0; i < 4; i++){ for (int j = 0; j < 4; j++){ for (int ii = 0; ii < 4; ii++){ for (int jj = 0; jj < 4; jj++){ if (dp[tt][i][j][ii][jj] == 13) return cout << i << ' ' << j << ' ' << ii << ' ' << jj, 0; ans = max(ans, dp[tt][i][j][ii][jj]); } } } } 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...