Submission #1067954

# Submission time Handle Problem Language Result Execution time Memory
1067954 2024-08-21T06:04:37 Z Oz121 Mobile (BOI12_mobile) Java 11
0 / 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);
            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 50 ms 22624 KB Output is correct
2 Correct 49 ms 18668 KB Output is correct
3 Incorrect 47 ms 12240 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 16076 KB Output is correct
2 Correct 52 ms 16132 KB Output is correct
3 Correct 58 ms 12800 KB Output is correct
4 Incorrect 56 ms 14036 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 18180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 24492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 25452 KB Output is correct
2 Correct 92 ms 20784 KB Output is correct
3 Incorrect 116 ms 18340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 107 ms 16976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 267 ms 35388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 240 ms 39780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 335 ms 41316 KB Output is correct
2 Incorrect 326 ms 38908 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 268 ms 44480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 269 ms 42168 KB Output is correct
2 Incorrect 261 ms 44236 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 127732 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1030 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 481 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 530 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 453 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 468 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 386 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 408 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 391 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 424 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -