# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
549971 | colossal_pepe | Skyline (IZhO11_skyline) | C++17 | 2096 ms | 47964 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstring>
using namespace std;
/*
dp[i][carry][carry, pass forward] = min cost for range [i...n]
*/
const int INF = 1e9;
int n, h[301], dp[301][201][201];
int brutus(int i, int c1, int c2) {
if (i >= n) return 0;
if (dp[i][c1][c2] != -1) return dp[i][c1][c2];
int h_cur = h[i] - c1 - c2;
dp[i][c1][c2] = INF;
for (int cnt3 = 0; cnt3 <= h_cur; cnt3++) {
for (int cnt2 = 0; cnt2 <= h_cur - cnt3; cnt2++) {
dp[i][c1][c2] = min(dp[i][c1][c2], brutus(i + 1, c2 + cnt2, cnt3) + 7 * cnt3 + 5 * cnt2 + 3 * (h_cur - cnt3 - cnt2));
}
}
return dp[i][c1][c2];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof(dp));
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
cout << brutus(0, 0, 0) << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |