제출 #870787

#제출 시각아이디문제언어결과실행 시간메모리
870787TurkhuuBuilding Bridges (CEOI17_building)C++17
30 / 100
12 ms2140 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = 1e18; ll s(int x) { return (ll)x * x; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> h(n), w(n); for (int &i : h) cin >> i; for (int &i : w) cin >> i; if (n <= 1000) { vector<ll> dp(n, inf); dp[0] = -w[0]; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { dp[i] = min(dp[i], dp[j] + s(h[i] - h[j]) - w[i]); } } for (int i : w) dp[n - 1] += i; cout << dp[n - 1]; } else { ll ans = inf; vector<ll> mx(41, -inf); for (int i = 1; i < n - 1; i++) { for (int j = 0; j <= 40; j++) { ans = min(ans, s(j - 20 - h[0]) + s(h[i] - h[n - 1]) + s(j - 20 - h[i]) - mx[j] - w[i]); } mx[h[i] + 20] = max(mx[h[i] + 20], (ll)w[i]); } for (int i = 1; i < n - 1; i++) { ans += w[i]; } cout << ans; } return 6/22; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...