Submission #588251

#TimeUsernameProblemLanguageResultExecution timeMemory
588251inluminasSkyline (IZhO11_skyline)C++17
100 / 100
105 ms50656 KiB
#include"bits/stdc++.h" using namespace std; #define ll long long #define inf LLONG_MAX #define fastio ios_base::sync_with_stdio(false) #define endl "\n" #define l first #define r second vector<vector<vector<int> > > dp (302,vector<vector<int>>(202,vector<int>(202,1e9))); vector<vector<int>> sev (202,vector<int>(202,1e9)); int main(){ fastio; int n; cin>>n; int h[n+1]; for(int i=1;i<=n;i++) cin>>h[i]; dp[1][0][0]=h[1]*3; for(int i=2;i<=n;i++){ for(int j=0;j<202;j++) fill(sev[j].begin(),sev[j].end(),1e9); for(int j=h[i-1];j>=0;j--){ for(int k=h[i-1]-j;k>=0;k--){ sev[j][k]=min(dp[i-1][h[i-1]-j-k][j],min(sev[j+1][k],sev[j][k+1])); } } for(int j=0;j<=h[i];j++){ for(int k=0;k<=h[i]-j;k++){ int l=h[i]-j-k; if(h[i-1]-j-k<0) continue; dp[i][j][k]=min(dp[i][j][k],sev[j][k]+2*j+2*k+3*l); } } } int ans=1e9; for(int j=0;j<=h[n];j++) for(int k=0;k<=h[n]-j;k++){ ans=min(ans,dp[n][j][k]); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...