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 <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <array>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <list>
#include <float.h>
#include <climits>
using namespace std;
void quit(){
cout.flush();
exit(0);
}
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() {
//freopen("qwer.in", "r", stdin);
//freopen("qwer.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> l;
towers.resize(n);
for(int i = 0; i < n; i++){
cin >> towers[i].first >> towers[i].second;
}
double s = 0, e = 300000, mid;
while(e-s>0.0001){
mid = (s+e)/2;
if(good(mid)){
e=mid;
}
else{
s=mid;
}
}
cout << e << "\n";
quit();
}
# | 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... |