Submission #603088

#TimeUsernameProblemLanguageResultExecution timeMemory
603088wiwihoShortcut (IOI16_shortcut)C++14
0 / 100
1 ms212 KiB
#include "shortcut.h" #include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define ef(a) emplace_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define tomax(a, b) ((a) = max((a), (b))) #define tomin(a, b) ((a) = min((a), (b))) #define topos(a) ((a) = (((a) % MOD + MOD) % MOD)) #define uni(a) a.resize(unique(iter(a)) - a.begin()) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 1LL << 60; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } ll ifloor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a < 0) return (a - b + 1) / b; else return a / b; } ll iceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a > 0) return (a + b - 1) / b; else return a / b; } int n; vector<ll> p, d, s; ll c; vector<ll> discr; vector<ll> tmp; vector<ll> pos; vector<ll> mnq, mxq; struct event{ ll x, y1, y2, ty; bool operator<(event b){ return x < b.x; } }; bool check(ll t){ vector<event> ev; for(int a = n - 1; a >= 0; a--){ ll X = t - d[a] - c; int id = upper_bound(iter(discr), t - d[a] + p[a]) - discr.begin(); if(id < n){ ll mny = -X + mxq[id]; ll mxy = X + mnq[id]; if(mny > mxy) return false; mny *= 2; mxy *= 2; ll midx = p[a] * 2; ll midy = (mny + mxy) / 2; ll r = mxy - midy; ll mnx = midx - r; ll mxx = midx + r; ll x1 = mnx - midy; ll x2 = mxx - midy; ll y1 = mnx + midy; ll y2 = mxx + midy; ev.eb(event({x1, y1, y2, 0})); ev.eb(event({x2 + 1, y1, y2, 1})); } } ll y1 = -MAX, y2 = MAX; ll x1 = -MAX, x2 = MAX; lsort(ev); int sz = ev.size(); int cnt = 0; for(int i = 0; i < sz; ){ ll x = ev[i].x; int tc = 0; bool ed = false; for(; i < sz && ev[i].x == x; i++){ if(ev[i].ty == 1){ x2 = x - 1; ed = true; break; } y1 = max(y1, ev[i].y1); y2 = min(y2, ev[i].y2); x1 = x; tc++; } if(y1 > y2 || ed) break; cnt += tc; } if(y1 > y2 || cnt != sz / 2) return false; for(int i = 0; i < n; i++){ ll x = p[i] * 2; ll mny = max(y1 - x, x - x2); ll mxy = min(y2 - x, x - x1); auto it = lower_bound(iter(p), iceil(mny, 2)); if(it != p.end() && *it * 2 <= mxy) return true; } return false; } ll find_shortcut(int _n, vector<int> len, vector<int> _d, int _c){ n = _n; c = _c; p.resize(n); s.resize(n); d.resize(n); for(int i = 0; i < n; i++) d[i] = _d[i]; for(int i = 0; i < n - 1; i++){ p[i + 1] = p[i] + len[i]; } for(int i = 0; i < n; i++){ s[i] = p[i] + d[i]; } discr = s; tmp.resize(n); pos.resize(n); mnq.resize(n); mxq.resize(n); iota(iter(tmp), 0); sort(iter(tmp), [&](int x, int y){ return s[x] < s[y]; }); for(int i = 0; i < n; i++){ pos[tmp[i]] = i; } lsort(discr); for(int i = n - 1; i >= 0; i--){ mnq[i] = -d[tmp[i]] + p[tmp[i]]; mxq[i] = d[tmp[i]] + p[tmp[i]]; if(i < n - 1){ mnq[i] = min(mnq[i], mnq[i + 1]); mxq[i] = max(mxq[i], mxq[i + 1]); } } ll l = 1, r = (1LL << 30) * n + 2e9 + 5; while(l < r){ ll m = (l + r) / 2; if(check(m)) r = m; else l = m + 1; } return l; }
#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...