Submission #1169856

#TimeUsernameProblemLanguageResultExecution timeMemory
1169856MinhKienBuilding Bridges (CEOI17_building)C++20
0 / 100
47 ms65348 KiB
#include <iostream> using namespace std; #define ll long long const int N = 1e5 + 10; const int M = 1e6 + 10; const ll INF = 1e18; int n; ll h[N], w[N], dp[N]; struct lichao { struct line { ll a, b; line() {a = b = INF;} line(ll A, ll B) {a = A, b = B;} ll calc(ll val) {return a == INF ? INF : a * val + b;} ll slope() {return a;} } st[M << 2]; void update(int l, int r, line f, int id) { int m = (l + r) >> 1; if (st[id].calc(m) > f.calc(m)) swap(st[id], f); if (l == r) return; if (f.slope() > st[id].slope()) update(m + 1, r, f, id << 1); if (f.slope() < st[id].slope()) update(l, m, f, id << 1 | 1); } ll get(int l, int r, int u, int id) { ll cur = st[id].calc(u); if (l == r) return cur; int m = (l + r) >> 1; if (u <= m) return min(cur, get(l, m, u, id << 1)); return min(cur, get(m + 1, r, u, id << 1 | 1)); } } Tree; int main() { cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) cin >> h[i]; for (int i = 1; i <= n; ++i) { cin >> w[i]; w[i] += w[i - 1]; } dp[1] = 0; Tree.update(0, 1e6, lichao::line(-2 * h[1], h[1] * h[1] - w[1]), 1); for (int i = 2; i <= n; ++i) { dp[i] = Tree.get(0, 1e6, h[i], 1) + h[i] * h[i] + w[i - 1]; Tree.update(0, 1e6, lichao::line(-2 * h[i], h[i] * h[i] + dp[i] - w[i]), 1); } cout << dp[n] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...