Submission #1066736

# Submission time Handle Problem Language Result Execution time Memory
1066736 2024-08-20T06:00:18 Z Oz121 Mobile (BOI12_mobile) Java 11
50 / 100
1000 ms 131072 KB
import java.io.*;
import java.util.*;
public class mobile {
    public static int num; public static double[][] arr;
    public static void main(String[] args) throws IOException {
        FastIO io = new FastIO(); num = io.nextInt(); int L = io.nextInt(); arr = new double[num][2];
        for (int i = 0;i<num;i++) {
            arr[i][0] = io.nextInt(); arr[i][1] = io.nextInt();
        }

        double l = 0; double h = Math.pow(10,9);
        while (h-l>Math.pow(10,-3)) {
            double mid = (l+h)/2; boolean work = true;
            ArrayList<Pair> endpoints = getEndpoints(mid);
            endpoints.sort(Comparator.comparingDouble(i -> i.l));

            if (endpoints.isEmpty()) {l = mid; continue;}

            double right = endpoints.get(0).r;
            for (int i = 1;i<endpoints.size();i++) {
                double newL = endpoints.get(i).l;
                if (newL>right&&newL>0&&newL<L) work = false;
                right = Math.max(right, endpoints.get(i).r);
            }
            work = (work)&&(endpoints.get(0).l<=0&&right>=L);

            if (work) h = mid;
            else l = mid;
        }

        io.println((l+h)/2); io.close();
    }

    public static ArrayList<Pair> getEndpoints (double r) {
        ArrayList<Pair> endpoints = new ArrayList<>();
        for (int i = 0;i<num;i++) {
            if (r*r-arr[i][1]*arr[i][1]<0) continue;
            endpoints.add(new Pair(arr[i][0]-Math.sqrt(r*r-arr[i][1]*arr[i][1]),
                            arr[i][0]+Math.sqrt(r*r-arr[i][1]*arr[i][1])));
        }
        return endpoints;
    }

    public static class Pair {
        double l; double r;
        public Pair (double l, double r) {
            this.l = l; this.r = r;
        }
    }

    public static class FastIO extends PrintWriter {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        private int curChar;
        private int numChars;

        // standard input
        public FastIO() { this(System.in, System.out); }

        public FastIO(InputStream i, OutputStream o) {
            super(o);
            stream = i;
        }
        public FastIO(String i, String o) throws IOException {
            super(new FileWriter(o));
            stream = new FileInputStream(i);
        }
        // throws InputMismatchException() if previously detected end of file
        private int nextByte() {
            if (numChars == -1) { throw new InputMismatchException(); }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) { throw new InputMismatchException(); }
                if (numChars == -1) {
                    return -1;  // end of file
                }
            }
            return buf[curChar++];
        }
        public int nextInt() {  // nextLong() would be implemented similarly
            int c;
            do { c = nextByte(); } while (c <= ' ');

            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = nextByte();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9') { throw new InputMismatchException(); }
                res = 10 * res + c - '0';
                c = nextByte();
            } while (c > ' ');
            return res * sgn;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 55 ms 9916 KB Output is correct
2 Correct 68 ms 9308 KB Output is correct
3 Correct 60 ms 9828 KB Output is correct
4 Correct 57 ms 9656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 10580 KB Output is correct
2 Correct 74 ms 10544 KB Output is correct
3 Correct 70 ms 10452 KB Output is correct
4 Correct 64 ms 10020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 15264 KB Output is correct
2 Correct 124 ms 13276 KB Output is correct
3 Correct 174 ms 15172 KB Output is correct
4 Correct 138 ms 13308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 15492 KB Output is correct
2 Correct 114 ms 13752 KB Output is correct
3 Correct 224 ms 16248 KB Output is correct
4 Correct 181 ms 15480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 16076 KB Output is correct
2 Correct 117 ms 13852 KB Output is correct
3 Correct 288 ms 16404 KB Output is correct
4 Correct 175 ms 15688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 13536 KB Output is correct
2 Correct 118 ms 13960 KB Output is correct
3 Correct 330 ms 16648 KB Output is correct
4 Correct 175 ms 15432 KB Output is correct
5 Correct 240 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 402 ms 28224 KB Output is correct
2 Correct 729 ms 29172 KB Output is correct
3 Correct 447 ms 25140 KB Output is correct
4 Correct 451 ms 29176 KB Output is correct
5 Correct 521 ms 22952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 516 ms 31188 KB Output is correct
2 Correct 571 ms 26116 KB Output is correct
3 Correct 516 ms 29144 KB Output is correct
4 Correct 447 ms 30292 KB Output is correct
5 Correct 439 ms 28704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 296 ms 29148 KB Output is correct
2 Correct 810 ms 29892 KB Output is correct
3 Correct 366 ms 29864 KB Output is correct
4 Correct 428 ms 27188 KB Output is correct
5 Correct 516 ms 29248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 480 ms 34444 KB Output is correct
2 Correct 814 ms 35364 KB Output is correct
3 Correct 752 ms 33736 KB Output is correct
4 Correct 365 ms 27176 KB Output is correct
5 Correct 578 ms 34280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 399 ms 33556 KB Output is correct
2 Correct 816 ms 35416 KB Output is correct
3 Correct 650 ms 33736 KB Output is correct
4 Correct 395 ms 27592 KB Output is correct
5 Correct 517 ms 34120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 111812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 116968 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1033 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 124700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 593 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1104 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 553 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 383 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 706 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -