Submission #1067960

# Submission time Handle Problem Language Result Execution time Memory
1067960 2024-08-21T06:10:59 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 left = Integer.MAX_VALUE; double right = endpoints.get(0).r;
            for (int i = 1;i<endpoints.size();i++) { //If [left,right] and [endpoints.get(i).l,endpoints.get(i).r] overlap, take union
                double newL = endpoints.get(i).l; double newR = endpoints.get(i).r;
                if (newL<=right) right = Math.max(right, newR);
                if (left<=newR) left = Math.min(left, newL);
            }
            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 56 ms 22552 KB Output is correct
2 Correct 52 ms 26248 KB Output is correct
3 Incorrect 50 ms 22136 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 20736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 22320 KB Output is correct
2 Correct 94 ms 25096 KB Output is correct
3 Incorrect 105 ms 24324 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 24716 KB Output is correct
2 Correct 96 ms 22516 KB Output is correct
3 Incorrect 107 ms 21056 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 25320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 103 ms 24572 KB Output is correct
2 Correct 90 ms 24968 KB Output is correct
3 Incorrect 93 ms 24996 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 257 ms 36492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 241 ms 37144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 338 ms 39252 KB Output is correct
2 Incorrect 331 ms 37780 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 270 ms 45056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 274 ms 42272 KB Output is correct
2 Incorrect 268 ms 44920 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 125400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 123264 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 487 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 521 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 450 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 513 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 407 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 488 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 411 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -