#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5;
int h[MAX_N];
long long 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[i - 1] - w[j] + (long long)(h[i] - h[j]) * (h[i] - h[j]) );
}
cout << dp[n - 1];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3051 ms |
3084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Execution timed out |
3051 ms |
3084 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |