# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568543 | nafis_shifat | Skyline (IZhO11_skyline) | C++17 | 1 ms | 852 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][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][k] = 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);
gp[2][i][h[2] - i] = min(gp[2][i][h[2] - i], dp[2][i][0]);
}
for(int i = h[2]; i >= 0; i--) {
for(int j = h[2]; j >= 0; j--) {
gp[2][i][j] = min({gp[2][i][j], gp[2][i + 1][j], gp[2][i][j + 1]});
}
}
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][i] + 2 * (i + j) + 3 * (h[p] - i - j);
gp[p][i][h[p] - i - j] = min(gp[p][i][h[p] - i - j], dp[p][i][j]);
}
}
for(int i = h[p]; i >= 0; i--) {
for(int j = h[p]; j >= 0; j--) {
gp[p][i][j] = min({gp[p][i][j], gp[p][i + 1][j], gp[p][i][j + 1]});
}
}
}
cout<<gp[n][0][0]<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |