#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll INF = 1e18;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> h(n + 1), w(n + 1);
for (int i = 1; i <= n; i += 1) {
cin >> h[i];
}
for (int i = 1; i <= n; i += 1) {
cin >> w[i];
}
vector<ll> dp(n + 1, INF);
dp[1] = 0;
for (int i = 1; i <= n; i += 1) {
ll sum = 0;
for (int j = i + 1; j <= n; j += 1) {
dp[j] = min(dp[j], dp[i] + (h[i] - h[j]) * (h[i] - h[j]) + sum);
sum += w[j];
}
}
cout << dp[n] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3091 ms |
3028 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Execution timed out |
3091 ms |
3028 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |