# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
582058 | 600Mihnea | Building Bridges (CEOI17_building) | C++17 | 0 ms | 212 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;
typedef long long ll;
const int N = (int) 1e5 + 7;
const ll INF = (ll) 1e18 + 7;
int n;
ll h[N];
ll sum[N];
ll dp[N];
signed main() {
#ifndef ONLINE_JUDGE
freopen ("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
h[i] = x;
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
sum[i] = sum[i - 1] + x;
}
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = INF;
}
for (int r = 2; r <= n; r++) {
for (int l = 1; l < r; l++) {
dp[r] = min(dp[r], dp[l] + (h[r] - h[l]) * (h[r] - h[l]) + sum[r - 1] - sum[l]);
}
}
cout << dp[n] << "\n";
}
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... |