이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5;
long long h[MAX_N], w[MAX_N], dp[MAX_N];
int main() {
int n;
cin >> n;
for ( int i = 0; i < n; i++ )
cin >> h[i];
for ( int i = 0; i < n; i++ )
cin >> w[i];
for ( int i = 1; i < n; i++ )
w[i] += w[i - 1];
for ( int i = 1; i < n; i++ ) {
dp[i] = 1e15;
for ( int j = 0; j < i; j++ )
dp[i] = min( dp[i], dp[j] - w[j] + h[j] * h[j] + h[i] * (-2 * h[j]) );
dp[i] += w[i - 1] + h[i] * h[i];
}
cout << dp[n - 1];
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... |