답안 #732971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732971 2023-04-29T22:47:56 Z williampsun Mobile (BOI12_mobile) Java 11
12 / 100
1000 ms 131072 KB
import java.io.*;
import java.util.*;

public class mobile {

    static int N;
    static int L;
    static int[][] 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 int[N][2];
        for(int i = 0; i < N; i++) {
            st = new StringTokenizer(br.readLine());
            coordinates[i][0] = Integer.parseInt(st.nextToken());
            coordinates[i][1] = Integer.parseInt(st.nextToken());
        }

        double left = 0;
        double right = 1500000000;
        double answer = 0;
        do {
            double mid = (left + right) / 2;
            boolean working = works(mid);
            if (working) {
                answer = mid;
                left = mid;
            } else {
                right = mid;
            }
        } while (Math.abs(left - right) > 0.0001);

        out.print(answer);
        out.close();
    }

    static boolean works(double radius) {
        ArrayList<Intercept> intercepts = new ArrayList<>();
        for(int[] c : coordinates) {
            int h = c[0];
            int k = c[1];
            double discriminant = radius * radius - k * k;
            if(discriminant > 0) {
                double sqrt = Math.sqrt(discriminant);
                intercepts.add(new Intercept(-sqrt + h, 1));
                intercepts.add(new Intercept(sqrt + h, 2));
            } else if (discriminant == 0) {
                intercepts.add(new Intercept(h, 0));
            }
        }

        if(intercepts.size() == 0) {
            return 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 false;
    }

    static class Intercept {
        double x;
        int type;

        public Intercept(double x, int t) {
            this.x = x;
            type = t;
        }
    }

    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;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 8692 KB Output is correct
2 Correct 67 ms 8608 KB Output is correct
3 Correct 64 ms 8576 KB Output is correct
4 Correct 66 ms 8652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 10968 KB Output is correct
2 Correct 107 ms 10936 KB Output is correct
3 Correct 120 ms 11348 KB Output is correct
4 Correct 107 ms 11500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 387 ms 14920 KB Output is correct
2 Correct 528 ms 15396 KB Output is correct
3 Correct 358 ms 14672 KB Output is correct
4 Correct 531 ms 15192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 15088 KB Output is correct
2 Correct 424 ms 15016 KB Output is correct
3 Correct 734 ms 15544 KB Output is correct
4 Incorrect 525 ms 15752 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 559 ms 15236 KB Output is correct
2 Correct 412 ms 14900 KB Output is correct
3 Correct 663 ms 15532 KB Output is correct
4 Incorrect 601 ms 15584 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 614 ms 15268 KB Output is correct
2 Correct 407 ms 15008 KB Output is correct
3 Correct 738 ms 15548 KB Output is correct
4 Incorrect 595 ms 15264 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 31720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 32384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1067 ms 27540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1062 ms 28972 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 38956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1076 ms 86288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1076 ms 77948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 99192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1074 ms 84184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1058 ms 102396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 101760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 923 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1076 ms 91996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1006 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1045 ms 119532 KB Time limit exceeded
2 Halted 0 ms 0 KB -