#include <bits/stdc++.h>
using namespace std;
#define int int64_t
vector<int> h;
vector<int> w;
vector<vector<int>> memo;
vector<vector<bool>> been;
int dp(int i, int last){
if(been[i][last])return memo[i][last];
been[i][last]=true;
if(i==(int)h.size()-1)return memo[i][last]=(h[i]-h[last])*(h[i]-h[last]);
int a=dp(i+1, i)+ (h[i]-h[last])*(h[i]-h[last]);
int b=dp(i+1,last)+w[i];
return memo[i][last]=min(a,b);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
h.resize(n);
w.resize(n);
for(int i=0;i<n;i++){
cin>>h[i];
}
for(int i=0;i<n;i++){
cin>>w[i];
}
memo.resize(n,vector<int> (n));
been.resize(n,vector<bool> (n));
int costs=dp(1,0);
cout<<costs<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
14 ms |
8432 KB |
Output is correct |
5 |
Correct |
15 ms |
8396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
89 ms |
131076 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
14 ms |
8432 KB |
Output is correct |
5 |
Correct |
15 ms |
8396 KB |
Output is correct |
6 |
Runtime error |
89 ms |
131076 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |