이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
constexpr int MAX_C = 3 * 10e9;
constexpr double tol = 0.00000001L;
using pi = pair<int, int>;
using pd = pair<double, double>;
int n, l;
vector<pi> towers;
bool doubleEq(double a, double b) {
return abs(a - b) <= tol;
}
double calcDist(int i, double d) {
return sqrt((d * d) - (towers[i].s * towers[i].s));
}
bool check(double p) {
// cout << "Called: " << p << endl;
vector<pd> intervals(n);
int idx = 0;
for(int i = 0; i < n; ++i) {
if(towers[i].s >= p || doubleEq(towers[i].s, p)) continue;
double dist = calcDist(i, p);
intervals[idx].f = towers[i].f - dist;
intervals[idx].s = towers[i].f + dist;
++idx;
}
// if(p - 6.98 <= 0.1) {
// cout << "------------------" << endl;
// for(int i = 0; i < n; ++i) cout << intervals[i].f << ' ' << intervals[i].s << endl;
// cout << "------------------" << endl;
// }
double start = intervals[0].f, curEnd = intervals[0].s, bestEnd = intervals[0].s;
for(auto& i: intervals) {
bestEnd = max(bestEnd, i.s);
if(i.f < curEnd || doubleEq(i.f, curEnd)) {
start = min(start, i.f);
curEnd = max(bestEnd, curEnd);
}
}
if((start < 0 || doubleEq(start, 0)) && (curEnd >= l || doubleEq(curEnd, l))) return true;
return false;
}
signed main() {
cin >> n >> l;
towers.resize(n);
for(pi& i: towers) cin >> i.f >> i.s;
double ans = MAX_C, b = MAX_C/2;
for(int i = 0; i < 50; ++i) {
if((ans - b) >= 0 && check(ans - b)) ans -= b;
b /= 2;
}
cout.precision(5);
cout << fixed << ans << '\n';
}
# | 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... |