# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
61787 | IvanC | Building Bridges (CEOI17_building) | C++17 | 3048 ms | 4656 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const ll INF = 1e18;
ll dp[MAXN],H[MAXN],W[MAXN],pref[MAXN],b[MAXN],a[MAXN];
int N;
int main(){
scanf("%d",&N);
for(int i = 1;i<=N;i++){
scanf("%lld",&H[i]);
}
for(int i = 1;i<=N;i++){
scanf("%lld",&W[i]);
pref[i] = W[i] + pref[i-1];
}
dp[1] = 0;
a[1] = -2*H[1];
b[1] = -pref[1] + dp[1] + H[1]*H[1];
for(int i = 2;i<=N;i++){
dp[i] = INF;
ll fixed_val = H[i]*H[i] + pref[i-1];
for(int j = 1;j<i;j++){
dp[i] = min(dp[i], a[j]*H[i] + b[j] + fixed_val );
}
a[i] = -2*H[i];
b[i] = -pref[i] + dp[i] + H[i]*H[i];
}
cout << dp[N] << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |