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 <bits/stdc++.h>
using namespace std;
int n, l;
vector <pair<double, double>> towers;
vector <pair<double ,double>> intervals;
bool good(double dist){
intervals.clear();
//get_intervals
double mx = 0;
for(const auto &tower : towers){
if(tower.second>dist){
intervals.emplace_back(0, 0);
continue;
}
double range = sqrt((dist*dist)-(tower.second*tower.second));
intervals.emplace_back(tower.first-range, tower.first+range);
mx = max(mx, tower.first+range);
}
sort(intervals.begin(), intervals.end());
if(intervals[0].first>0 || mx<l){
return false;
}
double curr_max = intervals[0].second;
for(int i = 1; i < (int) intervals.size(); i++){
if(intervals[i].first>l){
return true;
}
if(curr_max<intervals[i].first){
return false;
}
curr_max=max(curr_max, intervals[i].second);
}
return true;
}
int main() {
// your code goes here
cin >> n >> l;
towers.resize(n);
for(int i = 0; i < n; i++){
cin >> towers[i].first >> towers[i].second;
}
double s = 0, e = DBL_MAX/2, mid;
while(e-s>0.001){
mid = (s+e)/2;
if(good(mid)){
e=mid;
}
else{
s=mid;
}
}
cout << e << "\n";
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... |