제출 #253784

#제출 시각아이디문제언어결과실행 시간메모리
253784yanndevMiners (IOI07_miners)C++17
100 / 100
1219 ms100856 KiB
#include <iostream> #include <set> #include <map> const int MAX_FOOD = 1e5 + 1; const int NO_FOOD = 0; const int INF = 1e9; int dp[MAX_FOOD][4][4][4][4]; std::map<char, int> foodToInt {{'F', 1}, {'M', 2}, {'B', 3}}; int score(int a, int b, int c) { std::set<int> vals {a, b, c}; vals.erase(0); return vals.size(); } int main() { int n_delivery; int ans = 0; std::string deliveries; std::cin >> n_delivery >> deliveries; for (int i = 0; i <= n_delivery; i++) for (int lastFoodM11 = 0; lastFoodM11 < 4; lastFoodM11++) for (int lastFoodM12 = 0; lastFoodM12 < 4; lastFoodM12++) for (int lastFoodM21 = 0; lastFoodM21 < 4; lastFoodM21++) for (int lastFoodM22 = 0; lastFoodM22 < 4; lastFoodM22++) dp[i][lastFoodM11][lastFoodM12][lastFoodM21][lastFoodM22] = -INF; dp[0][NO_FOOD][NO_FOOD][NO_FOOD][NO_FOOD] = 0; for (int i = 0; i < n_delivery; i++) { int curFood = foodToInt[deliveries[i]]; for (int lastFoodM11 = 0; lastFoodM11 < 4; lastFoodM11++) for (int lastFoodM12 = 0; lastFoodM12 < 4; lastFoodM12++) for (int lastFoodM21 = 0; lastFoodM21 < 4; lastFoodM21++) for (int lastFoodM22 = 0; lastFoodM22 < 4; lastFoodM22++) if (dp[i][lastFoodM11][lastFoodM12][lastFoodM21][lastFoodM22] != -INF) { dp[i + 1][lastFoodM12][curFood][lastFoodM21][lastFoodM22] = std::max( dp[i + 1][lastFoodM12][curFood][lastFoodM21][lastFoodM22], dp[i][lastFoodM11][lastFoodM12][lastFoodM21][lastFoodM22] + score(lastFoodM11, lastFoodM12, curFood) ); dp[i + 1][lastFoodM11][lastFoodM12][lastFoodM22][curFood] = std::max( dp[i + 1][lastFoodM11][lastFoodM12][lastFoodM22][curFood], dp[i][lastFoodM11][lastFoodM12][lastFoodM21][lastFoodM22] + score(lastFoodM21, lastFoodM22, curFood) ); ans = std::max(ans, std::max( dp[i + 1][lastFoodM12][curFood][lastFoodM21][lastFoodM22], dp[i + 1][lastFoodM11][lastFoodM12][lastFoodM22][curFood] )); } } std::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...