Submission #1325669

#TimeUsernameProblemLanguageResultExecution timeMemory
1325669ghammazhassanSkyline (IZhO11_skyline)C++20
0 / 100
1 ms824 KiB
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
using namespace std;
#define int long long
#define endl "\n"
#define fi first
#define se second
const int M=998244353;
const int inf = 1e14;
const int LOG=17;
const int N=300+5;
const int O=200+5;
int n , m , c , w , k , t=1 , q=1 , x , y , z , l , r;
int dp[N][O];
void solve(){
    cin >> n;
    vector<int>a(n);
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    for (int i=0;i<N;i++){
        for (int j=0;j<O;j++){
            dp[i][j]=inf;
        }
    }
    dp[0][0]=0;
    for (int j=1;j<=a[0];j++){
        dp[0][j]=3*j;
    }
    for (int j=0;j<=a[1];j++){
        if (j==0)dp[1][j]=dp[0][a[0]];
        int u=min(a[0],j);
        dp[1][j]=5*u+3*(max(a[0],j)-u);
    }
    for (int i=2;i<n;i++){
        for (int j=0;j<=a[i];j++){
            if (j==0)dp[i][j]=dp[i-1][a[i-1]];
            dp[i][j]=dp[i][j-1]+3;
            dp[i][j]=min(dp[i][j],dp[i-1][a[i-1]]+3*j);
            int u=min({a[i],a[i-1],a[i-2]});
            for (int l=0;l<=u;l++){
                int u1=min(a[i],a[i-1])-l;
                dp[i][j]=min(dp[i][j],7*l+5*u1+3*(max(a[i],a[i-1])-l-u1)+dp[i-2][a[i-2]-l]);
            }
        }
    }
    cout << dp[n-1][a[n-1]] << endl;
}
signed main()    
{   
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r" ,stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE
    cout << fixed << setprecision(4);
    srand(time(0));
    // int t=1;
    // cin >> t;
    for (int _=1;_<=t;_++){
        solve();
        q++;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...