이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll INF = 1e18;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> h(n + 1), w(n + 1);
for (int i = 1; i <= n; i += 1) {
cin >> h[i];
}
vector<ll> pref(n + 1, 0);
for (int i = 1; i <= n; i += 1) {
cin >> w[i];
pref[i] = pref[i - 1] + w[i];
}
vector<ll> dp(n + 1, INF);
dp[1] = 0;
for (int i = 2; i <= n; i += 1) {
for (int j = 1; j < i; j += 1) {
dp[i] = min(dp[i], h[i] * -2 * h[j] + (dp[j] + h[j] * h[j] - pref[j]));
}
dp[i] += pref[i - 1] + h[i] * h[i];
}
cout << dp[n] << endl;
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... |