#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
struct date
{
ll h,w;
} v[100005];
ll dp[100005];
ll s[100005];
int main()
{
ios_base::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++)
cin>>v[i].h;
for(int i=1;i<=n;i++)
{
cin>>v[i].w;
s[i]=s[i-1]+v[i].w;
}
dp[1]=0;
for(int i=2;i<=n;i++)
{
dp[i]=1e17;
for(int j=i-1;j>=1;j--)
{
ll val=dp[j]+(v[i].h-v[j].h)*(v[i].h-v[j].h)+s[i-1]-s[j];
dp[i]=min(dp[i],val);
}
//cout<<dp[i]<<' ';
}
cout<<dp[n];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3044 ms |
4448 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3044 ms |
4448 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |