제출 #414631

#제출 시각아이디문제언어결과실행 시간메모리
414631DavidDamianMiners (IOI07_miners)C++11
100 / 100
237 ms110168 KiB
#include <bits/stdc++.h> using namespace std; int n; int food[100005]; int memo[100005][4][4][4][4]; int different(int a, int b, int c) { if (a > b) swap(a, b); if (b > c) swap(b, c); if (a > b) swap(a, b); int cnt = 1; if (a != b) { cnt++; } if (b != c) { cnt++; } if (a == 0) cnt--; return cnt; } int coal(int i, int X1, int X2, int Y1, int Y2) { if (i == n) return 0; if (memo[i][X1][X2][Y1][Y2] == -1) { int maximum = max(coal(i + 1, food[i], X1, Y1, Y2) + different(food[i], X1, X2), coal(i + 1, X1, X2, food[i], Y1) + different(food[i], Y1, Y2)); memo[i][X1][X2][Y1][Y2] = maximum; } return memo[i][X1][X2][Y1][Y2]; } int main() { memset(memo, -1, sizeof(memo)); cin >> n; for (int i = 0; i < n; i++) { char c; cin >> c; if (c == 'M') food[i] = 1; else if (c == 'F') food[i] = 2; else if (c == 'B') food[i] = 3; } int maximum = coal(0, 0, 0, 0, 0); cout << maximum << '\n'; 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...