#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];
}
vector<ll> pref(n + 1, 0);
for (int i = 1; i <= n; i += 1) {
cin >> w[i];
pref[i] = pref[i - 1] + w[i];
}
vector<ll> dp(n + 1, INF);
dp[1] = 0;
for (int i = 2; i <= n; i += 1) {
for (int j = 1; j < i; j += 1) {
dp[i] = min(dp[i], h[i] * -2 * h[j] + (dp[j] + h[j] * h[j] - pref[j]));
}
dp[i] += pref[i - 1] + h[i] * h[i];
}
cout << dp[n] << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3010 ms |
2648 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
480 KB |
Output is correct |
6 |
Execution timed out |
3010 ms |
2648 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |