Submission #481257

#TimeUsernameProblemLanguageResultExecution timeMemory
481257FatihSolakSkyline (IZhO11_skyline)C++17
100 / 100
229 ms1180 KiB
#include <bits/stdc++.h> #define N 305 using namespace std; int h[N]; void solve(){ int n; cin >> n; for(int i=1;i<=n;i++){ cin >> h[i]; } vector<vector<int>> dp(N,vector<int>(N,1e9)); dp[0][0] = 0; for(int x=1;x<=n;x++){ vector<vector<int>> ndp(N,vector<int>(N,1e9)); for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ ndp[max(0,j- i)][max(0,h[x] - i)] = min(ndp[max(0,j- i)][max(0,h[x] - i)],dp[i][j] + 7*i); } } for(int i=N-1;i>=0;i--){ for(int j=N-1;j>=0;j--){ ndp[i][max(0,j-1)] = min(ndp[i][max(0,j-1)],ndp[i][j] + 3); ndp[max(0,i-1)][max(0,j-1)] = min(ndp[max(0,i-1)][max(0,j-1)],ndp[i][j] + 5); } } dp = ndp; } cout << dp[0][0]; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t=1; //cin>>t; while(t--){ solve(); } #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...