#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
long long dp[N];
long long a[N];
long long b[N];
long long pref[N];
int main(){
ios_base::sync_with_stdio(false);
int n;
cin>>n;
for(int i = 1;i<=n;i++) cin>>a[i];
for(int i = 1;i<=n;i++){
cin>>b[i];
pref[i] = pref[i-1]+b[i];
dp[i] = 1000000000000000;
}
dp[1] = 0;
for(int i = 2;i<=n;i++){
for(int j = 1;j<i;j++){
dp[i] = min(dp[i],dp[j]+(a[i]-a[j])*(a[i]-a[j])+pref[i-1]-pref[j]);
}
}
cout<<dp[n]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
372 KB |
Output is correct |
4 |
Correct |
3 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
372 KB |
Output is correct |
4 |
Correct |
3 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
388 KB |
Output is correct |
6 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |