#include <bits/stdc++.h>
#define pow(x, y) (long double)(pow(x, y))
using namespace std;
struct coord{
int x, y;
};
vector <coord> a;
int N, L;
/*long double dis(int ax, ay, long double ans) {
return (long double)(sqrt(pow(ay, 2) + pow(ax - ans, 2)));
}
long double distance(int i, int j) {
long long num = pow(a[i].y, 2) - pow(a[j].y, 2) - pow(a[j].x, 2) + pow(a[i].x, 2);
long long den = 2 * (-a[j].x + a[i].x);
if (den == 0) return sqrt(num);
long double frac = (long double)(num) / (long double)(den);
return frac;
}*/
bool solve(long double mid) {
long double right(0);
for (int i(0); i < a.size(); i++) {
if (abs(a[i].y) > mid) continue;
long double iLeft = (long double)(a[i].x) - (long double)(sqrt(pow(mid, 2) - pow(a[i].y, 2)));
long double iRight = a[i].x + (a[i].x - iLeft);
if (iLeft <= right) right = max(right,iRight);
}
return (right >= L);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> L;
a.clear();
int x, y; cin >> x >> y;
a.push_back({x, y});
for (int i(0); i < N - 1; i++) {
int ax, ay;
cin >> ax >> ay;
a.push_back({ax, ay});
}
long double l(0), r(1e9);
long double ans(0);
while (r - l > 0.00001) {
long double mid = l + (r - l) / 2;
if (solve(mid)){
r = mid;
ans = r;
}
else l = mid;
}
cout << setprecision(5) << fixed << l << '\n';
return 0;
}
Compilation message
mobile.cpp: In function 'bool solve(long double)':
mobile.cpp:25:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<coord>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i(0); i < a.size(); i++) {
| ~~^~~~~~~~~~
mobile.cpp: In function 'int main()':
mobile.cpp:47:14: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
47 | long double ans(0);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1496 KB |
Output is correct |
2 |
Correct |
29 ms |
1496 KB |
Output is correct |
3 |
Correct |
19 ms |
992 KB |
Output is correct |
4 |
Correct |
23 ms |
1600 KB |
Output is correct |
5 |
Correct |
16 ms |
992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1496 KB |
Output is correct |
2 |
Correct |
22 ms |
1500 KB |
Output is correct |
3 |
Correct |
25 ms |
1496 KB |
Output is correct |
4 |
Correct |
27 ms |
1500 KB |
Output is correct |
5 |
Correct |
26 ms |
1500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
1748 KB |
Output is correct |
2 |
Correct |
32 ms |
1496 KB |
Output is correct |
3 |
Correct |
30 ms |
1496 KB |
Output is correct |
4 |
Correct |
32 ms |
1768 KB |
Output is correct |
5 |
Correct |
28 ms |
1500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
1436 KB |
Output is correct |
2 |
Correct |
38 ms |
1500 KB |
Output is correct |
3 |
Correct |
36 ms |
1496 KB |
Output is correct |
4 |
Correct |
28 ms |
1500 KB |
Output is correct |
5 |
Correct |
34 ms |
1496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
1496 KB |
Output is correct |
2 |
Correct |
37 ms |
1496 KB |
Output is correct |
3 |
Correct |
34 ms |
1500 KB |
Output is correct |
4 |
Correct |
32 ms |
1800 KB |
Output is correct |
5 |
Correct |
29 ms |
1500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
5064 KB |
Output is correct |
2 |
Correct |
203 ms |
5832 KB |
Output is correct |
3 |
Correct |
191 ms |
4856 KB |
Output is correct |
4 |
Correct |
128 ms |
5580 KB |
Output is correct |
5 |
Correct |
142 ms |
5332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
4704 KB |
Output is correct |
2 |
Correct |
253 ms |
6352 KB |
Output is correct |
3 |
Correct |
176 ms |
6016 KB |
Output is correct |
4 |
Correct |
139 ms |
4508 KB |
Output is correct |
5 |
Correct |
137 ms |
6084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
9404 KB |
Output is correct |
2 |
Correct |
224 ms |
10576 KB |
Output is correct |
3 |
Correct |
233 ms |
10404 KB |
Output is correct |
4 |
Correct |
158 ms |
8956 KB |
Output is correct |
5 |
Correct |
170 ms |
9148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
9660 KB |
Output is correct |
2 |
Correct |
325 ms |
10172 KB |
Output is correct |
3 |
Correct |
201 ms |
8704 KB |
Output is correct |
4 |
Correct |
156 ms |
10428 KB |
Output is correct |
5 |
Correct |
166 ms |
9404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
10172 KB |
Output is correct |
2 |
Correct |
271 ms |
10136 KB |
Output is correct |
3 |
Correct |
258 ms |
8896 KB |
Output is correct |
4 |
Correct |
184 ms |
9272 KB |
Output is correct |
5 |
Correct |
209 ms |
8640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
9920 KB |
Output is correct |
2 |
Correct |
333 ms |
10212 KB |
Output is correct |
3 |
Correct |
226 ms |
8896 KB |
Output is correct |
4 |
Correct |
184 ms |
9236 KB |
Output is correct |
5 |
Correct |
194 ms |
9404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
331 ms |
9924 KB |
Output is correct |
2 |
Correct |
286 ms |
9084 KB |
Output is correct |
3 |
Correct |
313 ms |
9424 KB |
Output is correct |
4 |
Correct |
219 ms |
8636 KB |
Output is correct |
5 |
Correct |
223 ms |
8892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
275 ms |
9060 KB |
Output is correct |
2 |
Correct |
365 ms |
9312 KB |
Output is correct |
3 |
Correct |
290 ms |
10172 KB |
Output is correct |
4 |
Correct |
207 ms |
9656 KB |
Output is correct |
5 |
Correct |
229 ms |
8956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
411 ms |
10336 KB |
Output is correct |
2 |
Correct |
382 ms |
10436 KB |
Output is correct |
3 |
Correct |
359 ms |
9880 KB |
Output is correct |
4 |
Correct |
264 ms |
9152 KB |
Output is correct |
5 |
Correct |
283 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
339 ms |
9152 KB |
Output is correct |
2 |
Correct |
448 ms |
9416 KB |
Output is correct |
3 |
Correct |
336 ms |
9692 KB |
Output is correct |
4 |
Correct |
269 ms |
9660 KB |
Output is correct |
5 |
Correct |
283 ms |
9496 KB |
Output is correct |