제출 #939080

#제출 시각아이디문제언어결과실행 시간메모리
939080vjudge1Building Bridges (CEOI17_building)C++17
30 / 100
3031 ms4172 KiB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector <int> h(n+1),w(n+1),pr(n+1),dp(n+1,1e18);
    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++)pr[i]=pr[i-1]+w[i];
    dp[1]=0;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=i-1;j++){
            dp[i]=min(dp[i],dp[j]+(h[i]-h[j])*(h[i]-h[j])+pr[i-1]-pr[j]);
        }
    }
    cout<<dp[n]<<"\n";
}
/*
6
3  8 7 1 6 6
0 -1 9 1 2 0
*/
           
 
           
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...