# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1051267 | vu28082007 | Building Bridges (CEOI17_building) | C++14 | 10 ms | 3804 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 taskname "mvu"
#define ll long long
#define fi first
#define se second
#define pb push_back
const int N = 1e5+7;
ll n, h[N], w[N], f[5007], b[N];
void sub1()
{
for (int i = 2; i <= n; i++)
{
for (int j = 1; j < i; j++)
{
f[i]=min(f[i], f[j]+(h[i]-h[j])*(h[i]-h[j]) + b[i-1]-b[j]);
}
}
cout << f[n];
}
void mvu()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
f[i]=1e18;
cin >> h[i];
}
f[1]=0;
for (int i = 1; i <= n; i++)
{
cin >> w[i];
if(i > 1 && i < n) b[i]=b[i-1]+w[i];
}
if (n <= 5000)
{
sub1();
return;
}
ll sum1=0;
sum1=b[n-1]+(h[n]-h[1])*(h[n]-h[1]);
for (int i =2; i < n; i++)
{
sum1=min(sum1, (b[n-1]-w[i]) + (h[i]-h[1])*(h[i]-h[1]) + (h[i]-h[n])*(h[i]-h[n]));
}
cout << sum1;
}
int main()
{
if(fopen(taskname".inp","r"))
{
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
mvu();
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... |