// oh, these hills, they burn so bright / oh, these hills, they bring me life
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x.size())
#define inf 1000000010
#define linf 0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define f first
#define s second
#define pi pair<int, int>
#ifdef LOCAL
#include "/mnt/c/yukon/pp.hpp"
#else
#define endl '\n'
#endif
#define double long double
struct Point {
double x, y;
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, l;
cin >> n >> l;
function<double(Point, Point)> max_point = [&](Point a, Point b) {
return (((b.x) * (b.x)) + ((b.y) * (b.y)) - ((a.x) * (a.x)) - ((a.y) * (a.y))) / (2 * (b.x - a.x));
};
function<double(Point, Point)> dist = [&](Point a, Point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
};
vector<Point> stck(n);
vector<Point> todo;
int idx = 0;
for (int i = 0; i < n; i++) {
Point cur;
cin >> cur.x >> cur.y;
if (idx > 1 && todo.back().x > max_point(stck[idx - 2], cur)) {
idx--;
todo.pop_back();
}
stck[idx] = cur;
if (idx) {
todo.push_back(Point{max_point(stck[idx - 1], cur), 0});
}
idx++;
}
double ans = max(dist({0, 0}, stck[0]), dist({l, 0}, stck[idx - 1]));
for (int x = 0; x < sz(todo); x++) {
ans = max({ans, dist(todo[x], stck[x + 1]), dist(todo[x], stck[x])});
}
cout << fixed << setprecision(6) << ans << endl;
}
// don't get stuck on one approach
// question bounds
// flesh out your approach before implementing o.o
// math it out
// ok well X is always possible, how about X + 1 (etc.)
Compilation message
mobile.cpp: In function 'int main()':
mobile.cpp:60:48: warning: narrowing conversion of 'l' from 'int' to 'long double' [-Wnarrowing]
60 | double ans = max(dist({0, 0}, stck[0]), dist({l, 0}, stck[idx - 1]));
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
600 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
604 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
600 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
3800 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
5076 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
8904 KB |
Output is correct |
2 |
Incorrect |
32 ms |
5444 KB |
Expected double, but "inf" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
5584 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
5680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
32656 KB |
Output is correct |
2 |
Incorrect |
226 ms |
33600 KB |
Expected double, but "inf" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
194 ms |
32696 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
52656 KB |
Output is correct |
2 |
Incorrect |
236 ms |
53268 KB |
Expected double, but "inf" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
254 ms |
53600 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
248 ms |
56720 KB |
Output is correct |
2 |
Incorrect |
293 ms |
55992 KB |
Expected double, but "inf" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
326 ms |
57436 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
285 ms |
59068 KB |
Output is correct |
2 |
Incorrect |
311 ms |
59668 KB |
Expected double, but "inf" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
318 ms |
58968 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
353 ms |
64688 KB |
Output is correct |
2 |
Incorrect |
385 ms |
64868 KB |
Expected double, but "inf" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
402 ms |
65604 KB |
Expected double, but "inf" found |
2 |
Halted |
0 ms |
0 KB |
- |