이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |