# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
104260 | luciocf | Building Bridges (CEOI17_building) | C++14 | 53 ms | 2952 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const long long inf = 2e18+10;
typedef long long ll;
int n;
int ind[60];
ll menor[60];
ll h[maxn], w[maxn];
ll cost(int i, int j)
{
return (h[j]-h[i])*(h[j]-h[i]);
}
int main(void)
{
int add = 20;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &h[i]);
ll S = 0ll;
for (int i = 1; i <= n; i++)
{
scanf("%lld", &w[i]);
if (i != 1 && i != n)
S += w[i];
}
ll ans = cost(1, n)+S;
for (int i = 2; i < n; i++)
ans = min(ans, cost(1, i)+cost(i, n)+S-w[i]);
for (int i = 0; i <= 40; i++)
menor[i] = inf, ind[i] = -1;
menor[w[2]+add] = h[2];
ind[w[2]+add] = 2;
for (int i = 3; i < n; i++)
{
for (int j = 0; j <= 40; j++)
{
if (ind[j] == -1) continue;
ans = min(ans, cost(1, ind[j])+cost(ind[j], i)+cost(i, n)+S-w[i]-w[ind[j]]);
}
if (h[i] < menor[w[i]+add])
menor[w[i]+add] = h[i], ind[w[i]+add] = i;
}
printf("%lld\n", ans);
}
컴파일 시 표준 에러 (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... |