Submission #972123

#TimeUsernameProblemLanguageResultExecution timeMemory
972123efedmrlrBuilding Bridges (CEOI17_building)C++17
30 / 100
3044 ms2652 KiB
#include <bits/stdc++.h> #define lli long long int #define ld long double #define pb push_back #define MP make_pair #define REP(i, n) for(int i = 0; (i) < (n); (i)++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const int N = 1e5 + 5; const lli INF = 1e17; vector<int> h(N), w(N); vector<lli> dp(N, INF), pr(N, 0); void solve() { int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> h[i]; } for(int i = 1; i <= n; i++) { cin >> w[i]; } for(int i = 1; i <= n; i++) { pr[i] = pr[i - 1] + w[i]; } dp[1] = 0; for(int i = 2; i <= n; i++) { for(int j = 1; j < i; j++) { dp[i] = min(dp[i], -2 * h[j] * h[i] + (h[j] * h[j] - pr[j] + dp[j]) + pr[i - 1] + h[i] * h[i]); } } cout << dp[n] << "\n"; } signed main() { fastio(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...