Submission #343917

# Submission time Handle Problem Language Result Execution time Memory
343917 2021-01-04T17:57:57 Z skurada A Huge Tower (CEOI10_tower) Java 11
90 / 100
1000 ms 53492 KB
import java.util.*;
import java.io.*;

public class tower {

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public float nextFloat() {
            return Float.parseFloat(next());
        }

        public double nextDouble() {
            return Float.parseFloat(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

    static class CPMath {
        static int add(int a, int b) {
            a += b;

            if (a >= mod) a -= mod;

            return a;
        }

        static int sub(int a, int b) {
            a -= b;
            if (a < 0) a += mod;
            return a;
        }

        static int multiply(int a, long b) {
            b = a * b;
            return (int) (b % mod);
        }

        static int divide(int a, int b) {
            return multiply(a, inverse(b));
        }

        static int inverse(int a) {
            return power(a, mod - 2);
        }

        static int power(int a, int b) {
            int r = 1;

            while (b > 0) {
                if (b % 2 == 1) {
                    r = multiply(r, a);
                }

                a = multiply(a, a);
                b /= 2;
            }

            return r;
        }
    }

    static InputReader sc;
    static PrintWriter pw;

    static int mod = (int) (1e9 + 9);

    public static void main(String[] args) throws Exception {
        sc = new InputReader(System.in);
        pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int d = sc.nextInt();

        Integer[] towers = new Integer[n];

        for (int i = 0; i < n; i++) {
            towers[i] = sc.nextInt();
        }

        Arrays.sort(towers, Collections.reverseOrder());

        int right_pointer = 0;
        int result = 1;

        for (int i = 0; i < n; i++) {
            while (right_pointer + 1 < n && towers[right_pointer + 1] + d >= towers[i]) {
                right_pointer++;
            }

            result = CPMath.multiply(result, right_pointer - i + 1);
        }

        pw.println(result);
        pw.close();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 8828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 8556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 8912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 9732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 12060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 774 ms 14548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 999 ms 17880 KB Output is correct
2 Correct 907 ms 18504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 30740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 53492 KB Time limit exceeded
2 Halted 0 ms 0 KB -