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 "shortcut.h"
#include "bits/stdc++.h"
#define ll long long
using namespace std;
//x+y, y-x (45 degrees rotation)
//|x-xx|+|y-yy| -> max(|x-xx|, |y-yy|)
const ll INF = 1e18;
bool check(ll k, vector<int> &d, int c, vector<ll>&p){
int n = d.size();
ll X = -INF, Y = -INF;
ll XX = INF, YY = INF;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++){
if (d[i] + d[j] + p[j] - p[i] <= k)
continue;
ll r = k - c - d[i] - d[j];
ll x = p[i] + p[j] - r, y = p[j] - p[i] - r;
ll xx = p[i] + p[j] + r, yy = p[j] - p[i] + r;
X = max(X, x); Y = max(Y, y);
XX = min(XX, xx); YY = min(YY, yy);
}
if (X > XX or Y > YY)
return 0;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++){
ll x = p[i] + p[j], y = p[j] - p[i];
if (X <= x and x <= XX and Y <= y and y <= YY)
return 1;
}
return 0;
}
ll find_shortcut(int n, vector<int> l, vector<int> d, int c){
vector<ll> p(n);
for (int i = 0; i < n-1; i++)
p[i+1] = p[i] + l[i];
ll st = 0, en = INF;
while (st < en){
ll mid = (st+en) >> 1;
if (check(mid, d, c, p))
en = mid;
else
st = mid + 1;
}
return st;
}
# | 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... |