Submission #525142

#TimeUsernameProblemLanguageResultExecution timeMemory
525142TheKingAleksSkyline (IZhO11_skyline)C++14
0 / 100
2080 ms460 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAX_N = 302; const int MAX_H = 202; const int INF = 1e9+7; int n,dp[MAX_N][MAX_H],a[MAX_N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=0; i<=MAX_N; i++) { for(int j=0; j<=MAX_H; j++) { dp[i][j] = INF; } } for(int i=1; i<=n; i++) cin>>a[i]; for(int j=0; j<=a[1]; j++) { dp[1][j] = (a[1]-j)*3; } if(n == 1) { cout<<dp[n][0]<<endl; return 0; } for(int x=0; x<=a[2]; x++) { int mini = min(a[2]-x,a[1]); dp[2][x] = (mini*5+(a[1]-mini)*3+(a[2]-x-mini)*3); } if(n == 2) { cout<<dp[n][0]<<endl; return 0; } for(int i=3; i<=n; i++) { for(int x=0; x<=a[i]; x++) { int tmp = 0; int last_val = min({a[i-2],a[i-1],a[i]-x}); for(int j=0; j<=last_val; j++) { tmp = dp[i-2][j]+j*7; int mini = min(a[i]-x-j,a[i-1]-j); tmp += mini*5; tmp += (a[i-1]-j-mini)*3+(a[i]-x-j-mini)*3; dp[i][x] = min(dp[i][x],tmp); tmp = 0; } } } cout<<dp[n][0]<<endl; }

Compilation message (stderr)

skyline.cpp: In function 'int main()':
skyline.cpp:18:22: warning: iteration 202 invokes undefined behavior [-Waggressive-loop-optimizations]
   18 |             dp[i][j] = INF;
      |             ~~~~~~~~~^~~~~
skyline.cpp:16:23: note: within this loop
   16 |         for(int j=0; j<=MAX_H; j++)
      |                      ~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...