# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1110909 | luvna | Building Bridges (CEOI17_building) | C++14 | 3035 ms | 2640 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>
#define all(v) v.begin(), v.end()
#define endl "\n"
#define sz(v) (int)(v).size()
#define int long long
using namespace std;
typedef long long ll;
const int N = 1e5 + 15;
const ll INF = 1e18;
int n;
int h[N];
ll dp[N];
int w[N];
ll sum(int l, int r){
if(l > r) return 0;
ll res = 0;
for(int i = l; i <= r; i++) res += w[i];
return res;
}
void solve(){
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 = 2; i <= n; i++){
dp[i] = INF;
for(int j = i-1; j >= 1; j--){
dp[i] = min(dp[i], 1LL*(h[i]-h[j])*(h[i]-h[j]) + sum(j+1,i-1) + dp[j]);
}
}
cout << dp[n];
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".ANS", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |