# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1051267 | vu28082007 | Building Bridges (CEOI17_building) | C++14 | 10 ms | 3804 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |