이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<array<int,2>> points;
int n, l;
auto comp = [](pair<double,double> a, pair<double,double> b){
return (a.first != b.first) ? a.first < b.first : a.second < b.second;
};
bool test(double r)
{
vector<pair<double,double>> v;
for (int i = 0; i < n; i++)
{
double h = points[i][0]; // x val of center
double k = points[i][1];
if (r <= k)
{
continue;
}
double len = sqrt(pow(r,2)-pow(k,2));
//cout << "LEG LENGTH: "<<len<<endl;
pair<double,double> p = make_pair(h-len, h+len);
v.push_back(p);
}
sort(v.begin(), v.end(), comp);
/*
for (auto pii : v)
{
cout << pii.first << " - " << pii.second << endl;
}
*/
// pairs all sorted
double ma = -1;
for (int i = 0; i < v.size(); i++)
{
if (v[i].second < v[i+1].first)
{
return false;
}
ma = max(max(v[i].second,v[i+1].second),ma);
}
return v[0].first <= 0 && ma >= l;
}
int main()
{
cin >> n >> l;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
points.push_back(array<int,2>{{a,b}});
}
auto comp = [](array<int,2> a, array<int,2> b) {
return a[0] < b[0];
};
sort(points.begin(), points.end(), comp);
//cout << "ANS: " << ((test(5)) ? "WORKS" : "DOESNT WORK") << endl;
double lo = 0;
double hi = 1500000000; // longest r needed is 10e9 sqrt2
while (lo < hi) // better precision than needed just to be safe
{
double mid = lo+(hi-lo)/2;
if (test(mid))
{
hi = mid;
}
else
{
lo = mid+0.00001;
}
}
cout << lo << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
mobile.cpp: In function 'bool test(double)':
mobile.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
# | 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... |