제출 #585514

#제출 시각아이디문제언어결과실행 시간메모리
585514talant117408Building Bridges (CEOI17_building)C++17
30 / 100
3043 ms8100 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define pb push_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define lb lower_bound #define ub upper_bound #define sz(v) int((v).size()) #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' void solve() { int n; cin >> n; vector <ll> h(n), w(n), pref(n); for (auto &to : h) cin >> to; for (auto &to : w) cin >> to; pref[0] = w[0]; for (int i = 1; i < n; i++) { pref[i] = pref[i - 1] + w[i]; } vector <vector <ll>> dp(n, vector <ll> (2, 2e18)); dp[0][1] = 0; for (int i = 1; i < n; i++) { for (int j = i - 1; j >= 0; j--) { dp[i][0] = min(dp[i][0], min(dp[j][0], dp[j][1]) + pref[i] - pref[j]); dp[i][1] = min(dp[i][1], dp[j][1] + pref[i - 1] - pref[j] + (h[i] - h[j]) * (h[i] - h[j])); } } cout << dp[n - 1][1]; } /* 6 3 8 7 1 6 6 0 -1 9 1 2 0 */ int main() { do_not_disturb int t = 1; //~ cin >> t; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...