This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
vector<int> pfs = {0};
vector<int> mem;
int dp(vector<pair<int, int>>& pillars, int lenght) {
if (lenght == 0) {
return 0;
}
if (mem[lenght] != 1e17) return mem[lenght];
int res = 1e17;
for (int i = 0; i<lenght; i++) {
res = min(res, dp(pillars, i) + (pfs[lenght] - pfs[i+1]) + (pillars[i].first - pillars[lenght].first) * (pillars[i].first - pillars[lenght].first));
}
return mem[lenght] = res;
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n; cin >> n;
mem.assign(n, 1e17);
vector<pair<int, int>> pillars(n);
for (int i = 0; i<n; i++) {
cin >> pillars[i].first;
}
for (int i = 0; i<n; i++) {
cin >> pillars[i].second;
pfs.push_back(pfs.back() + pillars[i].second);
}
pillars[0].second = 0;
pillars.back().second = 0;
cout << dp(pillars, n-1) << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |