# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334172 | apostoldaniel854 | Skyline (IZhO11_skyline) | C++14 | 98 ms | 48108 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 <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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |