#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2488 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3043 ms |
2712 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2488 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Execution timed out |
3043 ms |
2712 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |