#include <bits/stdc++.h>
using namespace std;
long long inf = 2e18;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
long long arr[n];
for(long long &i : arr){
cin >> i;
}
long long w[n];
for(long long &i : w){
cin >> i;
}
long long dp[n];
dp[0]=0;
dp[1]=(arr[0]-arr[1])*(arr[0]-arr[1]);
for(long long i = 2;i<n;i++){
long long sm = 0;
dp[i]=inf;
for(long long j = i-1;j>=0;j--){
dp[i]=min(dp[i],dp[j]+sm+(arr[i]-arr[j])*(arr[i]-arr[j]));
sm+=w[j];
}
}
cout << dp[n-1];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3042 ms |
3408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Execution timed out |
3042 ms |
3408 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |