# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
588243 | inluminas | Skyline (IZhO11_skyline) | C++17 | 38 ms | 50596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)));
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=1;j<=h[i-1];j++){
for(int k=h[i-1]-j;k>=0;k--){
dp[i-1][j][k]=min(dp[i-1][j][k],min(dp[i-1][j-1][k],dp[i-1][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],dp[i-1][h[i-1]-j-k][j]+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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |