Submission #870464

#TimeUsernameProblemLanguageResultExecution timeMemory
870464cpptowinBuilding Bridges (CEOI17_building)C++17
100 / 100
38 ms14864 KiB
#include <bits/stdc++.h> #define fo(i, d, c) for (int i = d; i <= c; i++) #define fod(i, c, d) for (int i = c; i >= d; i--) #define maxn 1000010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout << "\n"; #define int long long #define inf 1000000000 #define pii pair<int, int> #define vii vector<pii> #define lb(x) x & -x #define bit(i, j) ((i >> j) & 1) #define offbit(i, j) (i ^ (1 << j)) #define onbit(i, j) (i | (1 << j)) #define vi vector<int> using namespace std; using ll = long long; const ll INFL = 1e18; struct line { ll m, b; line() { m = 0, b = INFL; } line(ll m, ll b) : m(m), b(b) { } ll get(ll x) { return m * x + b; } }; struct LiChao { struct node { node *l, *r; line x; node(line x) : x(x) { l = r = 0; } }; node *t = new node(line()); void upd(line x, node *&v, int l = 0, int r = maxn) { if (!v) { v = new node(x); return; } int m = (l + r) / 2; bool lf = x.get(l) < v->x.get(l); bool md = x.get(m) < v->x.get(m); if (md) swap(x, v->x); if (l == r) return; if (lf != md) upd(x, v->l, l, m); else upd(x, v->r, m+1, r); } ll get(int x, node *&v, int l = 0, int r = maxn) { if (!v) return INFL; int m = (l + r) / 2; if (l == r) return v->x.get(x); if (x < m) return min(v->x.get(x), get(x, v->l, l, m)); else return min(v->x.get(x), get(x, v->r, m+1, r)); } void add(line x) { return upd(x, t); } ll get(int x) { return get(x, t); } }cht; int n; int h[maxn]; int w[maxn]; int pre[maxn]; int dp[maxn]; main() { #define name "TASK" if (fopen(name ".inp", "r")) { freopen(name ".inp", "r", stdin); freopen(name ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; fo(i, 1, n) cin >> h[i]; fo(i, 1, n) { cin >> w[i]; pre[i] = pre[i - 1] + w[i]; } cht.add({-2 * h[1], h[1] * h[1] - w[1]}); dp[1] = 0; fo(i, 2, n) { dp[i] = cht.get(h[i]) + pre[i - 1] + h[i] * h[i]; cht.add({-2 * h[i],h[i] * h[i] - pre[i] + dp[i]}); } cout << dp[n]; }

Compilation message (stderr)

building.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
building.cpp: In function 'int main()':
building.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...