Submission #96932

#TimeUsernameProblemLanguageResultExecution timeMemory
96932youngyojunShortcut (IOI16_shortcut)C++11
97 / 100
2073 ms61192 KiB
#include "shortcut.h" #include <bits/stdc++.h> #define INFLL (0x3f3f3f3f3f3f3f3fll) using namespace std; typedef long long ll; inline void upmin(ll &a, ll b) { if(b < a) a = b; } inline void upmax(ll &a, ll b) { if(a < b) a = b; } const int MAXN = 1000055; ll X[MAXN], L[MAXN]; int O[MAXN], OJ[MAXN]; int N; ll K, Ans; bool isp(ll Y) { ll xymx = -INFLL, xymn = INFLL, yxmx = -INFLL, yxmn = INFLL; ll mx[2] = {-INFLL, -INFLL}, mn[2] = {INFLL, INFLL}; int mxi[2] = {-1, -1}, mni[2] = {-1, -1}; for(int oi = 0, i, oj = 0, j; oj < N; oj++) { j = OJ[oj]; for(ll t = Y-X[j]-L[j], c; oi < N; oi++) { i = O[oi]; if(L[i]-X[i] <= t) break; c = X[i]+L[i]; if(mx[0] < c) { swap(mx[0], c); swap(mxi[0], i); } if(mx[1] < c) { swap(mx[1], c); swap(mxi[1], i); } i = O[oi]; c = X[i]-L[i]; if(c < mn[0]) { swap(mn[0], c); swap(mni[0], i); } if(c < mn[1]) { swap(mn[1], c); swap(mni[1], i); } } ll rmx = j == mxi[0] ? mx[1] : mx[0]; ll rmn = j == mni[0] ? mn[1] : mn[0]; upmin(xymn, Y-K + rmn + X[j]-L[j]); upmax(xymx, K-Y + rmx + X[j]+L[j]); upmin(yxmn, Y-K - rmx + X[j]-L[j]); upmax(yxmx, K-Y - rmn + X[j]+L[j]); } for(int s = 0, xymxi = N-1, xymni = N-1, yxmxi = 0, yxmni = 0; s < N; s++) { for(ll t = xymx-X[s]; xymxi && t <= X[xymxi-1]; xymxi--); for(ll t = xymn-X[s]; 0 <= xymni && t < X[xymni]; xymni--); for(ll t = yxmx+X[s]; yxmxi < N && X[yxmxi] < t; yxmxi++); for(ll t = yxmn+X[s]; yxmni+1 < N && X[yxmni+1] <= t; yxmni++); if(X[xymxi] < xymx-X[s] || yxmn+X[s] < X[yxmni]) continue; if(max(xymxi, yxmxi) <= min(xymni, yxmni)) return true; } return false; } ll getAns() { ll mx = -INFLL; for(int i = 0; i < N; i++) { upmax(Ans, X[i]+L[i] + mx); upmax(mx, L[i]-X[i]); } iota(O, O+N, 0); sort(O, O+N, [&](int a, int b) { return L[a]-X[a] > L[b]-X[b]; }); iota(OJ, OJ+N, 0); sort(OJ, OJ+N, [&](int a, int b) { return X[a]+L[a] < X[b]+L[b]; }); ll a = 0, b = 0; for(int i = 0; i < N; i++) { ll c = L[i]; if(a < c) swap(a, c); if(b < c) swap(b, c); } ll s = a+b, e = Ans; for(ll m; s < e;) { m = (s+e) >> 1; if(isp(m)) e = m; else s = m+1; } return min(Ans, s); } long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) { ::N = n; ::K = c; for(int i = 1; i < N; i++) ::X[i] = ::X[i-1] + l[i-1]; for(int i = 0; i < N; i++) ::L[i] = d[i]; return getAns(); }
#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...