Submission #550934

#TimeUsernameProblemLanguageResultExecution timeMemory
550934colossal_pepeSkyline (IZhO11_skyline)C++17
100 / 100
179 ms56128 KiB
#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 timeMemoryGrader output
Fetching results...