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) {
vector<array<long long, 4>> sq;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
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;
}
sq.push_back({x[i] + x[j] - r, x[j] - r - x[i], x[i] + x[j] + r, x[j] + r - x[i]});
}
}
long long xl = -inf, xr = inf;
long long yl = -inf, yr = inf;
for (auto& p : sq) {
xl = max(xl, p[0]);
xr = min(xr, p[2]);
yl = max(yl, p[1]);
yr = min(yr, p[3]);
}
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 = i + 1, R = n - 1;
if (plx == n || x[i] + x[plx] < xl) {
continue;
}
L = max(L, plx);
if (prx == -1 || x[i] + x[prx] > xr) {
continue;
}
R = min(R, prx);
if (ply == n) {
continue;
}
L = max(L, ply);
if (pry == -1) {
continue;
}
R = min(R, 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... |