이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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};
int dp(vector<pair<int, int>>& pillars, int lenght) {
if (lenght == 0) {
return 0;
}
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 res;
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n; cin >> n;
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... |