| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 853319 | manizare | Building Bridges (CEOI17_building) | C++14 | 3036 ms | 9860 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>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define Pii pair< pii , pii >
#define int long long
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 4e5 + 10 , maxq = 1e7 + 1 , inf = 1e8 + 10 , mod= 998244353 ,lg = 20 ;
int dp[maxn] , h[maxn] , w[maxn];
signed main(){
ios::sync_with_stdio(false); cin.tie(0) ;
int n ;
cin >> n;
for(int i =1 ; i<= n ;i++){
cin >> h[i] ;
}
int ans= 0 ;
for(int i = 1; i <= n ; i++){
cin >> w[i] ;
}
for(int i = 2; i <= n ; i++){
int sm =0 ;
dp[i] = inf ;
for(int j = i-1 ; j >= 1; j--){
dp[i] = min(sm + (h[i] - h[j]) * (h[i] - h[j]) + dp[j], dp[i]) ;
sm += w[j] ;
}
}
cout << dp[n] ;
}
/*
*/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... | ||||
