#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
skyline.cpp: In function 'int main()':
skyline.cpp:18:15: warning: iteration 201 invokes undefined behavior [-Waggressive-loop-optimizations]
18 | dp[i][j][k] = inf;
| ~~~~~~~~~~~~^~~~~
skyline.cpp:17:77: note: within this loop
17 | for(int i = 0; i <= n; i++) for(int j = 0; j <= mxv; j++) for(int k = 0; k <= mxv; k++) {
| ~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |