# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550934 | colossal_pepe | Skyline (IZhO11_skyline) | C++17 | 179 ms | 56128 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[305], dp[305][205][205];
int brutus(int i, int j, int k) {
if (i > n + 1) return 0;
if (dp[i][j][k] != -1) return dp[i][j][k];
if (j == 0) dp[i][j][k] = brutus(i + 1, k, h[i + 1]);
else {
dp[i][j][k] = brutus(i, j - 1, k) + 3;
if (min(j, k) > 0) dp[i][j][k] = min(dp[i][j][k], brutus(i, j - 1, k - 1) + 5);
if (j <= k and j <= h[i + 1]) dp[i][j][k] = min(dp[i][j][k], brutus(i + 1, k - j, h[i + 1] - j) + 7 * j);
}
return dp[i][j][k];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof(dp));
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
h[0] = 0, h[n + 1] = 0;
cout << brutus(1, h[0], h[1]) << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |