Submission #1345287

#TimeUsernameProblemLanguageResultExecution timeMemory
1345287datBuilding Bridges (CEOI17_building)C++20
30 / 100
3094 ms3540 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int Nmax = 1e5 + 5;

int n;
ll h[Nmax], w[Nmax];
ll preW[Nmax], dp[Nmax];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    for(int i = 1; i <= n; i++) cin >> h[i];
    for(int i = 1; i <= n; i++) cin >> w[i];

    for(int i = 1; i <= n; i++){
        preW[i] = preW[i - 1] + w[i];
    }

    dp[1] = 0;

    for(int i = 2; i <= n; i++){
        dp[i] = 1e18;

        for(int j = 1; j < i; j++){
            ll cost = dp[j]
                    + (preW[i - 1] - preW[j])
                    + (h[i] - h[j]) * (h[i] - h[j]);

            dp[i] = min(dp[i], cost);
        }
    }

    cout << dp[n];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...