Submission #548366

#TimeUsernameProblemLanguageResultExecution timeMemory
548366Soumya1Skyline (IZhO11_skyline)C++17
100 / 100
116 ms736 KiB
#include <bits/stdc++.h> #ifdef __LOCAL__ #include <debug_local.h> #endif using namespace std; const int mxN = 301; const int mxH = 201; const int inf = 1e9; int h[mxN]; void testCase() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; vector<vector<int>> dp(mxH, vector<int> (mxH, inf)); for (int i = h[1]; i >= 0; i--) { dp[0][i] = (h[1] - i) * 3; } for (int i = 2; i <= n; i++) { vector<vector<int>> new_dp(mxH, vector<int> (mxH, inf)); for (int cur = 0; cur <= h[i]; cur++) { for (int last = 0; last <= h[i - 1]; last++) { if (last + h[i] - cur <= h[i - 1]) { new_dp[last][cur] = min(new_dp[last][cur], dp[h[i] - cur][last + h[i] - cur] + (h[i] - cur) * 7); } } } dp = new_dp; for (int cur = h[i]; cur >= 0; cur--) { for (int last = h[i - 1]; last >= 0; last--) { if (last - 1 >= 0) { dp[last - 1][cur] = min(dp[last - 1][cur], dp[last][cur] + 3); } if (cur - 1 >= 0 && last - 1 >= 0) { dp[last - 1][cur - 1] = min(dp[last - 1][cur - 1], dp[last][cur] + 5); } if (cur - 1 >= 0) { dp[last][cur - 1] = min(dp[last][cur - 1], dp[last][cur] + 3); } } } } cout << dp[0][0] << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); testCase(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...