Submission #868289

#TimeUsernameProblemLanguageResultExecution timeMemory
868289Truly_Building Bridges (CEOI17_building)C++14
0 / 100
52 ms65428 KiB
#define nametask "bridgepol" #include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define SZ(a) (int) a.size() #define FOR(i, a, b) for (int i = a; i <= b; i++) #define FOD(i, b, a) for (int i = b; i >= a; i--) #define int long long using namespace std; typedef long long ll; typedef pair <int, int> pi; const int N = 1e5 + 5; const int oo = 1e12 + 7; const int MAX = 1e6; struct line{ int a, b; line(){ a = b = oo; } }; int n; int h[N], w[N]; int s[N]; line t[4 * MAX + 5]; int calc(line y, int x){ return (1LL * y.a * x + y.b); } void upd_it(int id, int l, int r, line y){ int mid = (l + r) / 2; if (calc(t[id], l) <= calc(y, l) && calc(t[id], r) <= calc(y, r)) return; if (calc(t[id], l) > calc(y, l) && calc(t[id], r) > calc(y, r)){ t[id] = y; return; } if (calc(t[id], l) <= calc(y, l) && calc(t[id], mid) <= calc(y, mid)){ upd_it(id * 2 + 1, mid + 1, r, y); return; } if (calc(t[id], l) > calc(y, l) && calc(t[id], mid) > calc(y, mid)){ upd_it(id * 2 + 1, mid + 1, r, t[id]); t[id] = y; return; } if (calc(t[id], mid + 1) <= calc(y, mid + 1) && calc(t[id], r) <= calc(y, r)){ upd_it(id * 2, l, mid, y); return; } if (calc(t[id], mid + 1) > calc(y, mid + 1) && calc(t[id], r) > calc(y, r)){ upd_it(id * 2, l, mid, t[id]); t[id] = y; return; } upd_it(id * 2, l, mid, y); upd_it(id * 2 + 1, mid + 1, r, y); } int get_it(int id, int l, int r, int u){ if (l > u || r < u) return ((ll)1e18); int mid = (l + r) / 2; ll res = calc(t[id], u); if (l == r) return res; res = min(res, get_it(id * 2, l, mid, u)); res = min(res, get_it(id * 2 + 1, mid + 1, r, u)); return res; } void solve(){ line tmp; tmp.a = -2 * h[1]; tmp.b = -w[1] + 1LL * h[1] * h[1]; upd_it(1, 1, MAX, tmp); FOR(i, 2, n - 1){ int val = get_it(1, 1, MAX, h[i]) - w[i] + 1LL * h[i] * h[i]; tmp.a = -2 * h[i]; tmp.b = val + 1LL * h[i] * h[i]; upd_it(1, 1, MAX, tmp); } cout << s[n] + get_it(1, 1, MAX, h[n]) - w[n] + 1LL * h[n] * h[n]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); if (fopen(nametask".inp", "r")){ freopen(nametask".inp", "r", stdin); freopen(nametask".out", "w", stdout); } cin >> n; FOR(i, 1, n) cin >> h[i]; FOR(i, 1, n) cin >> w[i]; FOR(i, 1, n) s[i] = s[i - 1] + w[i]; solve(); return 0; }

Compilation message (stderr)

building.cpp: In function 'int main()':
building.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(nametask".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(nametask".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...