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>
using namespace std;
long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
vector<long long> x(n);
for (int i = 1; i < n; i++) {
x[i] = x[i - 1] + l[i - 1];
}
const long long inf = (long long) 1e18;
auto Check = [&](long long diam) {
long long xl = -inf, xr = inf;
long long yl = -inf, yr = inf;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
continue;
}
if (d[i] + d[j] + x[j] - x[i] <= diam) {
continue;
}
long long r = diam - d[i] - d[j] - c;
if (r < 0) {
return false;
}
xl = max(xl, x[i] + x[j] - r);
xr = min(xr, x[i] + x[j] + r);
yl = max(yl, x[j] - r - x[i]);
yr = min(yr, x[j] + r - x[i]);
}
}
int plx = n, prx = n - 1, ply = 0, pry = -1;
for (int i = 0; i < n; i++) {
while (plx > 0 && x[i] + x[plx - 1] >= xl) {
plx--;
}
while (prx >= 0 && x[i] + x[prx] > xr) {
prx--;
}
while (ply < n && x[ply] - x[i] < yl) {
ply++;
}
while (pry + 1 < n && x[pry + 1] - x[i] <= yr) {
pry++;
}
int L = max({i + 1, plx, ply}), R = min(prx, pry);
if (L <= R) {
return true;
}
}
return false;
};
long long low = 0, high = inf, ans = 0;
while (low <= high) {
long long mid = (low + high) >> 1;
if (Check(mid)) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
# | 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... |