# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568533 | nafis_shifat | Skyline (IZhO11_skyline) | C++17 | 1 ms | 596 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>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=300+5;
const int inf=1e9;
const int mxv = 201;
int n, h[mxn];
int dp[mxn][mxv][mxv];
int gp[mxn][mxv];
int main() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> h[i];
}
for(int i = 0; i <= n; i++) for(int j = 0; j <= mxv; j++) for(int k = 0; k <= mxv; k++) {
dp[i][j][k] = inf;
gp[i][j] = inf;
}
for(int i = 0; i <= min(h[1], h[2]); i++) {
dp[2][i][0] = 5 * i + 3 * (h[2] - i) + 3 * (h[1] - i);
}
for(int i = min(h[1], h[2]); i>= 0; i--) gp[2][i] = min(gp[2][i + 1], dp[2][i][0]);
for(int p = 3; p <= n; p++) {
for(int i = 0; i <= min(h[p], h[p - 1]); i++) {
for(int j = 0; j <= min(h[p] - i, h[p - 1] - i); j++) {
dp[p][i][j] = gp[p - 1][j] + 2 * (i + j) + 3 * (h[p] - i - j);
}
}
for(int i = mxv - 1; i >= 0; i--) {
gp[p][i] = inf;
for(int j = 0; j <= mxv; j++) gp[p][i] = min(gp[p][i], dp[p][i][j]);
gp[p][i] = min(gp[p][i], gp[p][i + 1]);
}
}
cout<<gp[n][0]<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |