# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221875 | MKopchev | Building Bridges (CEOI17_building) | C++14 | 3072 ms | 4108 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;
const int nmax=1e5+42;
int n;
long long h[nmax],w[nmax],pref[nmax];
long long dp[nmax];
int main()
{
scanf("%i",&n);
for(int i=1;i<=n;i++)scanf("%lld",&h[i]);
for(int i=1;i<=n;i++)scanf("%lld",&w[i]);
for(int i=1;i<=n;i++)pref[i]=pref[i-1]+w[i];
dp[1]=0;
for(int j=2;j<=n;j++)
{
dp[j]=1e18;
for(int i=j-1;i>=1;i--)
{
long long s_1=h[j]*h[j]+pref[j-1];
long long s_2=h[i]*h[i]-pref[i]+dp[i];
long long s_3=-2*h[i]*h[j];
dp[j]=min(dp[j],s_1+s_2+s_3);
}
//cout<<j<<" -> "<<dp[j]<<endl;
}
printf("%lld\n",dp[n]);
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... |