이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lli long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 1e5 + 5;
const lli INF = 1e17;
vector<int> h(N), w(N);
vector<lli> dp(N, INF), pr(N, 0);
void solve() {
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> h[i];
}
for(int i = 1; i <= n; i++) {
cin >> w[i];
}
for(int i = 1; i <= n; i++) {
pr[i] = pr[i - 1] + w[i];
}
dp[1] = 0;
for(int i = 2; i <= n; i++) {
for(int j = 1; j < i; j++) {
dp[i] = min(dp[i], dp[j] + (h[i] - h[j]) * (h[i] - h[j]) + pr[i - 1] - pr[j]);
}
}
cout << dp[n] << "\n";
}
signed main() {
fastio();
solve();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |