This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
ckmax(x.fi, a + c + b + d);
ckmin(x.se, a + c - b - d);
ckmax(y.fi, a - c + b + d);
ckmin(y.se, a - c - b - d);
//update(a + c - rem, a + c + rem, a - c - rem, a - c + rem)
}
}
x.fi += (D - s);
y.fi += (D - s);
x.se += (s - D);
y.se += (s - D);
// 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |