# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445802 | iulia13 | Skyline (IZhO11_skyline) | C++14 | 72 ms | 50616 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 INF = 1e9 + 5;
const int N = 305;
const int H = 205;
int dp[N][H][H]; ///dp[i][j][k] = sunt la cladirea i iar pe i mai am j iar pe i-1 mai am k
int h[N];
int main()
{
int n, i, j, k;
cin >> n;
for (i = 1; i <= n; i++)
cin >> h[i];
memset(dp, INF, sizeof dp);
for (i = 0; i <= h[1]; i++)
dp[2][h[2]][i] = dp[1][i][0] = 3 * (h[1] - i);
for (i = 2; i <= n; i++)
{
for (j = h[i]; 0 <= j; j--)
for (k = h[i - 1]; 0 <= k; k--)
dp[i][j][k] = min(dp[i][j][k], dp[i][j + 1][k] + 3);
for (j = h[i]; 0 <= j; j--)
for (k = h[i - 1]; 0 <= k; k--)
dp[i][j][k] = min(dp[i][j][k], dp[i][j + 1][k + 1] + 5);
for (int l = min(h[i + 1], min(h[i], h[i - 1])); 0 <= l; l--) ///atateam am scos din v[i - 1] ca tb sa l fac 0
for (j = h[i]; l <= j; j--)
dp[i + 1][h[i + 1] - l][j - l] = min(dp[i][j][l] + 7 * l, dp[i + 1][h[i + 1] - l][j - l]);
}
cout << dp[n][0][0];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |