Submission #151176

#TimeUsernameProblemLanguageResultExecution timeMemory
151176qkxwsmShortcut (IOI16_shortcut)C++14
71 / 100
2029 ms2228 KiB
#include <bits/stdc++.h> #include "shortcut.h" using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define y1 qwertyuiop #define y2 asdfghjkl #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) #define SZ(x) ((int) ((x).size())) #define ALL(x) (x).begin(), (x).end() #define MAXN 1000013 #define INF 1000000007 #define LLINF 2696969696969696969 typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; int N; ll D; pll arr[MAXN]; bool check(ll s) { pll x = {-LLINF, LLINF}, y = {-LLINF, LLINF}; FOR(i, 0, N) { ll a = arr[i].fi, b = arr[i].se; FOR(j, i + 1, N) { ll c = arr[j].fi, d = arr[j].se; if (d + b + c - a <= s) continue; ll rem = s - b - d - D; if (rem < 0) return false; ckmax(x.fi, a + c - rem); ckmin(x.se, a + c + rem); ckmax(y.fi, a - c - rem); ckmin(y.se, a - c + rem); //update(a + c - rem, a + c + rem, a - c - rem, a - c + rem) } } // cerr << s << ' ' << x.fi << ' ' << x.se << ' ' << y.fi << ' ' << y.se << endl; FOR(i, 0, N) { ll m = arr[i].fi; FOR(j, i + 1, N) { ll n = arr[j].fi; // cerr << m + n << ',' << m - n << endl; if (x.fi <= m + n && m + n <= x.se && y.fi <= m - n && m - n <= y.se) return true; } } return false; } ll find_shortcut(int n, vi l, vi d, int vs) { N = n; D = vs; l.insert(l.begin(), 0); FOR(i, 0, N) { arr[i].fi = l[i]; arr[i].se = d[i]; } FOR(i, 1, N) { arr[i].fi += arr[i - 1].fi; } // FOR(i, 0, N) // { // cerr << arr[i].fi << ' ' << arr[i].se << endl; // } ll lo = 0, hi = LLINF; while(hi > lo) { ll mid = (hi + lo) >> 1; if (check(mid)) hi = mid; else lo = mid + 1; } return lo; }
#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...