#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5 + 10;
const ll inf = (ll)1e18;
int h[N];
ll w[N];
ll dp[N];
ll sq(ll x){
return (x * 1ll * x);
}
int main(){
fastIO;
int n;
cin >> n;
for(int i = 1; i <= n; i ++ ){
cin >> h[i];
}
for(int i = 1; i <= n; i ++ ){
cin >> w[i];
w[i] += w[i - 1];
dp[i]=inf;
}
dp[1]=0;
for(int i = 2; i <= n; i ++ ){
for(int j = i - 1; j >= 1; j -- ){
dp[i]=min(dp[i],(w[i-1]-w[j])+sq(h[i]-h[j])+dp[j]);
}
}
cout << dp[n];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3071 ms |
3308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Execution timed out |
3071 ms |
3308 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |