Submission #334172

#TimeUsernameProblemLanguageResultExecution timeMemory
334172apostoldaniel854Skyline (IZhO11_skyline)C++14
100 / 100
98 ms48108 KiB
#include <bits/stdc++.h> using namespace std; const int H = 200, N = 300; int dp[1 + N][1 + H][1 + H]; int a[1 + N]; void upd (int &a, int b) { if (a > b) a = b; } int main () { ios::sync_with_stdio (false); cin.tie (0); cout.tie (0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 0; i <= n; i++) for (int j = 0; j <= H; j++) for (int k = 0; k <= H; k++) dp[i][j][k] = (1 << 30); for (int i = 1; i <= n; i++) { if (i == 1) dp[i][0][a[i]] = 0; /// push dp through the level for (int j = H; j >= 0; j--) for (int k = H; k >= 0; k--) { if (k) upd (dp[i][j][k - 1], dp[i][j][k] + 3); if (j && k) upd (dp[i][j - 1][k - 1], dp[i][j][k] + 5); } /// push dp to the next level if (i < n) for (int j = H; j >= 0; j--) for (int k = H; k >= 0; k--) if (a[i + 1] >= j && k >= j) upd (dp[i + 1][k - j][a[i + 1] - j], dp[i][j][k] + j * 7); } cout << dp[n][0][0] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...