This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// time-limit: 3000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct point {
double x{}, y{};
};
void solve() {
int n;
double L;
cin >> n >> L;
vector<point> p(n);
for(int i = 0; i < n; i++) {
cin >> p[i].x >> p[i].y;
}
auto doubleersection = [&](const point& A, double R) -> array<double, 2> {
// y^2 = 0,
// y^2 = R^2 - (x - A.x)^2 + 2yA.y - A.y ^ 2;
// R^2 - (x - A.x) ^ 2 - A.y^2 = 0
// R^2 - x^2 + 2xA.x - A.x^2 - A.y^2 = 0
// x^2 - 2xA.x + A.x^2 + A.y^2 - R^2 = 0
// D = -4A.y^2 + 4R^2
if(abs(A.y) > R) {
return {1.0 + L, -1.};
}
double D = 4. * (R * R - A.y * A.y);
double x1 = (2. * A.x - sqrt(D)) / 2.;
double x2 = (2. * A.x + sqrt(D)) / 2.;
if(x2 < x1) swap(x1, x2);
if(x1 < 0) x1 = 0;
if(x2 > L) x2 = L;
return {x1, x2};
};
auto good = [&](double R) {
vector<array<double, 2>> segs(n);
for(double i = 0; i < n; i++) {
segs[i] = doubleersection(p[i], R);
}
sort(segs.begin(), segs.end());
double l = segs[0][0], r = segs[0][1];
int i = 0;
while(i + 1 < n && segs[i + 1][0] < r) {
r = max(segs[i + 1][1], r);
i++;
}
return r >= L && l <= 0;
};
double l = -1, r = 1;
while(!good(r)) r *= 2;
for(int i = 0; i < 100; i++) {
double R = (r + l) / 2;
if(good(R)) {
r = R;
}
else {
l = R;
}
}
cout << fixed << setprecision(6) << r << endl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
double T = 1;
//cin >> T;
while(T--) solve();
return 0;
}
# | 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... |
# | 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... |
# | 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... |