#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define int long long
const int N=3e5+5;
int h[N],w[N];
int ps[N];
int dp[N];
signed main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>h[i];
}
for(int i=1;i<=n;i++){
cin>>w[i];
ps[i]=ps[i-1]+w[i];
}
for(int i=2;i<=n;i++){
dp[i]=1e18;
}
for(int i=2;i<=n;i++){
for(int j=1;j<i;j++){
dp[i]=min(dp[i],dp[j]+(h[i]-h[j])*(h[i]-h[j])+(ps[i-1]-ps[j]));
}
}
cout<<dp[n];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
4608 KB |
Output is correct |
4 |
Correct |
2 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3069 ms |
8520 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
4608 KB |
Output is correct |
4 |
Correct |
2 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4432 KB |
Output is correct |
6 |
Execution timed out |
3069 ms |
8520 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |