// https://oj.uz/problem/view/BOI12_mobile
#include <bits/stdc++.h>
using namespace std;
#define forint(i, from, toinc) for (int i = from; i <= toinc; ++i)
#define sq(x) (x)*(x)
#define all(x) x.begin(), x.end()
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef USEFILE
freopen("mobile.in", "r", stdin);
freopen("mobile.out", "w", stdout);
#endif
}
/*
some observations:
if we have 2 towers with the same x, (x, y1) and (x, y2),
we only need to keep the one with the smallest abs y value,
let's say |y1| <= |y2|, then we can safely forget (x, y2), because for any
point on the x axis, it will always be closer (<=) to (x, y1) than to (x, y2).
we do a simple binary search on distance d to see if all points between [0,L]
can be covered by d.
*/
struct Point {
int x,y;
};
struct Range {
double from, to;
bool operator<(const Range &o) const {
return from == o.from ? to < o.to : from < o.from;
}
};
int tcnt; // tower count
vector<Point> towers;
int len; // all points on (0,0) to (len,0) to the towers
vector<Range> ranges;
int rcnt;
void debug()
{
cerr << "highway from (0,0) to (" << len << ",0)" << endl;
cerr << tcnt << " towers:";
forint(i, 0, tcnt-1) {
cerr << " " << towers[i].x << "," << towers[i].y;
}
cerr << endl;
cerr << rcnt << " ranges:";
forint(i, 0, rcnt-1) {
cerr << " [" << ranges[i].from << "," << ranges[i].to << "]";
}
cerr << endl;
}
void rdata()
{
cin >> tcnt >> len;
int lastx, lasty; // lasty >= 0
cin >> lastx >> lasty;
lasty = abs(lasty);
forint(i, 1, tcnt-1) {
int x, y;
cin >> x >> y;
if (x != lastx) {
towers.push_back({lastx, lasty});
lastx = x;
lasty = abs(y);
} else if (abs(y) < abs(lasty)) {
lasty = abs(y);
}
if (i == tcnt-1) {
towers.push_back({lastx, lasty});
}
}
tcnt = (int)towers.size();
}
bool can_cover(double d)
{
ranges.clear();
forint(i, 0, tcnt-1) {
double x = towers[i].x;
double y = towers[i].y;
if (d > y) {
double dx = sqrt(sq(d) - sq(y));
ranges.push_back({x-dx, x+dx});
}
}
rcnt = (int)ranges.size();
sort(all(ranges));
int ri = 0;
while (ri < rcnt && ranges[ri].to < 0) {
ri++;
}
#ifdef DEBUG
debug();
#endif
double right = 0;
forint(i, ri, rcnt-1) {
if (ranges[i].from <= right) {
right = max(ranges[i].to, right);
}
}
bool res = right >= len;
#ifdef DEBUG
cerr << "d=" << d << " can" << (res ? "" : "not") << " cover all" << endl;
#endif
return res;
}
int main()
{
fio();
rdata();
#ifdef DEBUG
debug();
#endif
double dends2 = sq(towers[0].x + len) + sq(towers[0].y);
dends2 = max(dends2, sq(1.0 * towers[tcnt-1].x) + sq(towers[tcnt-1].y));
double dmax = sqrt(dends2);
double d = dmax+1;
for (double step = dmax; step > 1e-4; step /= 2) {
while (d >= 0 && can_cover(d-step)) {
d -= step;
}
}
cout << fixed << setprecision(3) << d << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
11 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
11 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
468 KB |
Output is correct |
2 |
Correct |
12 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
3028 KB |
Output is correct |
2 |
Correct |
168 ms |
2920 KB |
Output is correct |
3 |
Correct |
154 ms |
2520 KB |
Output is correct |
4 |
Correct |
29 ms |
3612 KB |
Output is correct |
5 |
Correct |
7 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
468 KB |
Output is correct |
2 |
Correct |
24 ms |
2140 KB |
Output is correct |
3 |
Correct |
28 ms |
3324 KB |
Output is correct |
4 |
Correct |
32 ms |
3688 KB |
Output is correct |
5 |
Correct |
34 ms |
3920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
3212 KB |
Output is correct |
2 |
Correct |
157 ms |
3032 KB |
Output is correct |
3 |
Correct |
383 ms |
3408 KB |
Output is correct |
4 |
Correct |
42 ms |
5196 KB |
Output is correct |
5 |
Correct |
21 ms |
1976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
1752 KB |
Output is correct |
2 |
Correct |
127 ms |
3180 KB |
Output is correct |
3 |
Correct |
64 ms |
1740 KB |
Output is correct |
4 |
Correct |
43 ms |
5156 KB |
Output is correct |
5 |
Correct |
35 ms |
3664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
267 ms |
3296 KB |
Output is correct |
2 |
Correct |
138 ms |
3192 KB |
Output is correct |
3 |
Correct |
60 ms |
1832 KB |
Output is correct |
4 |
Correct |
45 ms |
5204 KB |
Output is correct |
5 |
Correct |
34 ms |
4428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
813 ms |
12476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
752 KB |
Output is correct |
2 |
Correct |
834 ms |
19024 KB |
Output is correct |
3 |
Correct |
510 ms |
8968 KB |
Output is correct |
4 |
Correct |
211 ms |
21820 KB |
Output is correct |
5 |
Correct |
184 ms |
19472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1010 ms |
21532 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
544 KB |
Output is correct |
2 |
Execution timed out |
1006 ms |
29356 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
22260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
584 KB |
Output is correct |
2 |
Execution timed out |
1063 ms |
31556 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
23088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
488 KB |
Output is correct |
2 |
Execution timed out |
1051 ms |
33572 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1049 ms |
24624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
173 ms |
440 KB |
Output is correct |
2 |
Execution timed out |
1052 ms |
37788 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |