Submission #568552

#TimeUsernameProblemLanguageResultExecution timeMemory
568552nafis_shifatSkyline (IZhO11_skyline)C++17
0 / 100
1 ms980 KiB
#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 = 210; 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)

skyline.cpp: In function 'int main()':
skyline.cpp:18:15: warning: iteration 210 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++) {
      |                                                                           ~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...