이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y;
};
/**
* @return the intersection of the perpendicular line that
* crosses the midpoint of Points a & b with the highway
*/
double max_point(const Point &a, const Point &b) {
return (b.x * b.x + b.y * b.y - a.x * a.x - a.y * a.y) / (2 * b.x - 2 * a.x);
}
/** @return the euclidean distance between points a & b */
double dist(const Point &a, const Point &b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int main() {
int n, l;
cin >> n >> l;
deque<Point> needed;
for (int i = 0; i < n; i++) {
Point cur;
cin >> cur.x >> cur.y;
cur.y = abs(cur.y);
// always take the one with the lowest y coord
if ((int)needed.size() && needed.back().x == cur.x) {
if (cur.y >= needed.back().y) {
continue;
} else if (cur.y < needed.back().y) {
needed.pop_back();
}
}
// find "crosses"
while ((int)needed.size() > 1 &&
max_point(needed[(int)needed.size() - 2], needed.back()) >
max_point(needed.back(), cur)) {
needed.pop_back();
}
needed.push_back(cur);
}
// out of bounds
while ((int)needed.size() > 1 && max_point(needed[0], needed[1]) < 0) {
needed.pop_front();
}
while ((int)needed.size() > 1 &&
max_point(needed[(int)needed.size() - 2], needed.back()) > l) {
needed.pop_back();
}
double ans = 0;
for (int x = 0; x < (int)needed.size(); x++) {
// get critical points needed[x] is in charge of
Point left = {0, 0};
Point right{l, 0};
if (x) { left.x = max_point(needed[x], needed[x - 1]); }
if (x < (int)needed.size() - 1) {
right.x = max_point(needed[x], needed[x + 1]);
}
if (left.x < 0 || right.x > l || right.x < 0 || left.x > l) { continue; }
ans = max({ans, dist(needed[x], left), dist(needed[x], right)});
}
cout << fixed << setprecision(6) << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
mobile.cpp: In function 'int main()':
mobile.cpp:63:15: warning: narrowing conversion of 'l' from 'int' to 'double' [-Wnarrowing]
63 | Point right{l, 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... |