#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000006LL;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<ll> h(n);
for (int i = 0; i < n; i++) cin >> h[i];
vector<ll> w(n);
for (int i = 0; i < n; i++) cin >> w[i];
vector<ll> dp(n, INF);
dp[0] = 0;
for (int i = 1; i < n; i++) {
ll cost = 0;
for (int j = i - 1; j >= 0; j--) {
dp[i] = min(dp[i], dp[j] + cost + (h[i] - h[j]) * (h[i] - h[j]));
cost += w[j];
}
}
cout << dp[n - 1] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
3652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Execution timed out |
3073 ms |
3652 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |