Submission #333808

#TimeUsernameProblemLanguageResultExecution timeMemory
333808limabeansSkyline (IZhO11_skyline)C++17
100 / 100
358 ms232684 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl using ll = long long; const ll inf = 1e18; const int maxn = 314; int n; int a[maxn]; ll dp[maxn][maxn][maxn]; void setmin(ll &x, ll y) { x = min(x, y); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; for (int i=1; i<=n; i++) { cin>>a[i]; } for (int i=0; i<=n; i++) { for (int j=0; j<maxn; j++) { for (int k=0; k<maxn; k++) { dp[i][j][k] = inf; } } } dp[1][0][a[1]] = 0; for (int i=1; i<=n; i++) { for (int j=maxn-1; j>=0; j--) { for (int k=maxn-1; k>=0; k--) { if (k>0) { setmin(dp[i][j][k-1], dp[i][j][k]+3); } if (j>0 && k>0) { setmin(dp[i][j-1][k-1], dp[i][j][k]+5); } } } if (i==n) { break; } // j....k.....a[i+1] for (int j=0; j<maxn; j++) { for (int k=0; k<maxn; k++) { if (a[i+1] >= j && k >= j) { setmin(dp[i+1][k-j][a[i+1]-j], dp[i][j][k] + 7*j); } } } } cout<<dp[n][0][0]<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...