Submission #838024

#TimeUsernameProblemLanguageResultExecution timeMemory
838024pavementShortcut (IOI16_shortcut)C++17
71 / 100
2067 ms1368 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back using ll = long long; struct ds { set<pair<ll, ll> > S; void insert(ll x, ll y) { vector<set<pair<ll, ll> >::iterator> to_erase; // insert (x, y) auto it = S.lower_bound(mp(x, 0ll)); if (it != S.end() && it->second >= y) { return; } if (it == S.end() || it->first != x) { if (it == S.begin()) { S.emplace(x, y); return; } --it; } while (1) { if (it->second <= y) { to_erase.pb(it); } else { break; } if (it == S.begin()) { break; } --it; } for (auto it2 : to_erase) { S.erase(it2); } S.emplace(x, y); } ll query(ll k) { // max y over all x > k auto it = S.upper_bound(mp(k, (ll)1e18)); return it == S.end() ? -(ll)1e18 : it->second; } }; ll find_shortcut(int n, vector<int> l, vector<int> d, int c) { vector<ll> x(n, 0); for (int i = 0; i + 1 < n; i++) { x[i + 1] = x[i] + (ll)l[i]; } auto good = [&](ll k) { ll min_x = -(ll)1e18, max_x = (ll)1e18, min_y = -(ll)1e18, max_y = (ll)1e18; { ds S; for (int j = 1; j < n; j++) { S.insert(d[j - 1] - x[j - 1], x[j - 1] + d[j - 1]); min_x = max(min_x, S.query(k - d[j] - x[j]) - k + c + d[j] - x[j]); } } { ds S; for (int j = 1; j < n; j++) { S.insert(d[j - 1] - x[j - 1], -(x[j - 1] - d[j - 1])); max_x = min(max_x, -S.query(k - d[j] - x[j]) + k - c - d[j] - x[j]); } } { ds S; for (int j = 1; j < n; j++) { S.insert(d[j - 1] - x[j - 1], x[j - 1] + d[j - 1]); min_y = max(min_y, S.query(k - d[j] - x[j]) - k + c + d[j] + x[j]); } } { ds S; for (int j = 1; j < n; j++) { S.insert(d[j - 1] - x[j - 1], -(x[j - 1] - d[j - 1])); max_y = min(max_y, -S.query(k - d[j] - x[j]) + k - c - d[j] + x[j]); } } if (min_x <= max_x && min_y <= max_y) { for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (min_x <= x[i] - x[j] && x[i] - x[j] <= max_x && min_y <= x[i] + x[j] && x[i] + x[j] <= max_y) { return true; } } } return false; } else { return false; } }; ll lo = 0, hi = (ll)1e16, ans = -1; while (lo <= hi) { ll mid = (lo + hi) / 2ll; if (good(mid)) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...