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>
#ifdef LOCAL
#define dbg(x) cerr << "dgb: " << x << "\n";
#else
#define dbg(x)
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,tune=native")
#endif
#define int int_fast64_t
using namespace std;
const int INF = 1e17;
vector<int> hs;
vector<int> w;
int n;
vector<vector<int>> memo(1001, vector<int>(1001, INF));
int f(int i, int l) {
if (memo[i][l] != INF)
return memo[i][l];
if (i == 0)
return (hs[l] - hs[0]) * (hs[l] - hs[0]);
int best = f(i - 1, i) + (hs[i] - hs[l]) * (hs[i] - hs[l]);
if (i != n - 1)
best = min(best, f(i - 1, l) + w[i]);
return memo[i][l] = best;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
hs.resize(n);
w.resize(n);
for (int &x : hs)
cin >> x;
for (int &x : w)
cin >> x;
cout << f(n - 1, n - 1) << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |