import java.io.*;
import java.util.*;
public class mobile {
static int N;
static int L;
static boolean containsIntercept;
static ArrayList<Coordinate> coordinates;
public static void main(String[] args) throws IOException {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
try {
br = new BufferedReader(new FileReader("highcard.in"));
out = new PrintWriter(new BufferedWriter(new FileWriter("highcard.out")));
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
st = new StringTokenizer(br.readLine());
}
N = Integer.parseInt(st.nextToken());
L = Integer.parseInt(st.nextToken());
coordinates = new ArrayList<>();
for(int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
coordinates.add(new Coordinate(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())));
}
double left = 0;
double right = Integer.MAX_VALUE;
double answer = 0;
do {
// System.out.println(left + " " + right);
double mid = (left + right) / 2;
boolean working = works(mid);
if (working) {
answer = mid;
left = mid;
} else {
right = mid;
}
} while (!isEqual(left, right));
out.print(answer);
out.close();
}
static boolean works(double radius) {
ArrayList<Intercept> intercepts = new ArrayList<>();
int id = 0;
for(Coordinate c : coordinates) {
double[] theseInter = getIntercepts(c.x, c.y, radius);
if(theseInter.length == 2) {
intercepts.add(new Intercept(Math.min(theseInter[0], theseInter[1]), 1, id));
intercepts.add(new Intercept(Math.max(theseInter[0], theseInter[1]), 2, id));
id++;
} else if (theseInter.length == 1) {
intercepts.add(new Intercept(theseInter[0], 0, id));
id++;
}
}
if(intercepts.size() > 0) {
containsIntercept = true;
}
intercepts.sort(new Compare());
int numCircles = 0;
for (Intercept intercept : intercepts) {
if (intercept.x >= 0 && intercept.x <= L) {
if(numCircles == 0 || (numCircles == 1 && intercept.type == 2)) {
return true;
}
}
if (intercept.type == 1) {
numCircles++;
} else if (intercept.type == 2) {
numCircles--;
}
}
return intercepts.size() == 0;
}
static double[] getIntercepts(double h, double k, double radius) {
if(radius * radius - k * k > 0) {
double sqrt = Math.sqrt(radius * radius - k * k);
return new double[] {sqrt + h, -sqrt + h};
} else if (radius * radius - k * k == 0) {
return new double[] {h};
} else {
return new double[] {};
}
}
static boolean isEqual(double one, double two) {
return Math.abs(one - two) <= 0.001;
}
static class Coordinate {
int x;
int y;
public Coordinate(int x, int y) {
this.x = x;
this.y = y;
}
}
static class Intercept {
double x;
int type;
int id;
public Intercept(double x, int t, int id) {
this.x = x;
type = t;
this.id = id;
}
}
static class Compare implements Comparator<Intercept> {
@Override
public int compare(Intercept o1, Intercept o2) {
if(o1.x < o2.x) {
return -1;
} else if (o1.x == o2.x) {
return 0;
}
return 1;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
81 ms |
8584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
12260 KB |
Output is correct |
2 |
Correct |
125 ms |
12076 KB |
Output is correct |
3 |
Correct |
129 ms |
12292 KB |
Output is correct |
4 |
Correct |
150 ms |
12672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
428 ms |
15532 KB |
Output is correct |
2 |
Correct |
576 ms |
15256 KB |
Output is correct |
3 |
Correct |
455 ms |
15492 KB |
Output is correct |
4 |
Correct |
546 ms |
15164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
550 ms |
15532 KB |
Output is correct |
2 |
Correct |
486 ms |
15140 KB |
Output is correct |
3 |
Correct |
687 ms |
15856 KB |
Output is correct |
4 |
Correct |
595 ms |
15708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
641 ms |
15716 KB |
Output is correct |
2 |
Correct |
456 ms |
15316 KB |
Output is correct |
3 |
Correct |
693 ms |
15624 KB |
Output is correct |
4 |
Correct |
547 ms |
15680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
758 ms |
16008 KB |
Output is correct |
2 |
Correct |
457 ms |
15320 KB |
Output is correct |
3 |
Correct |
767 ms |
15644 KB |
Output is correct |
4 |
Correct |
503 ms |
15544 KB |
Output is correct |
5 |
Correct |
583 ms |
15860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
36708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
37768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1049 ms |
40424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
42736 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
31096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1058 ms |
93568 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1052 ms |
79328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
949 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1063 ms |
87888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
126676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1057 ms |
115140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1053 ms |
131072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
131072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
131072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1016 ms |
131072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |