# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
250245 | Pbezz | Building Bridges (CEOI17_building) | C++14 | 3053 ms | 4476 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>
using namespace std;
#define loop(i,n) for (ll i = 0; i < n; i++)
#define ll long long
#define INF 100000000005
#define MAXN 1000005
#define MOD 1000000000007
#define pb push_back
#define mp make_pair
typedef pair<ll,ll> pii;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n,i,j,k;
scanf("%lld",&n);
ll h[n];
ll w[n];
ll dp[n];
ll sum[n];
for(i=0;i<n;i++){
scanf("%lld",&h[i]);
}
for(i=0;i<n;i++){
scanf("%lld",&w[i]);
}
sum[0]=w[0];
for(i=1;i<n;i++){
sum[i]=sum[i-1]+w[i];
dp[i]=INF;
}
dp[0]=0;
for(i=1;i<n;i++){
for(j=i-1;j>=0;j--){
k=(h[i]-h[j])*(h[i]-h[j]);
k+=dp[j];
k+=(sum[i-1]-sum[j]);
dp[i]=min(dp[i],k);
}
}
printf("%lld\n",dp[n-1]);
return 0;
}
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... |