Submission #740780

# Submission time Handle Problem Language Result Execution time Memory
740780 2023-05-13T05:39:27 Z yeroc A Huge Tower (CEOI10_tower) Java 11
100 / 100
630 ms 51996 KB
import java.io.*;
import java.util.*;

public class tower {

    static void solve(Kattio io){
		int MOD = 1000000009;
		int n = io.nextInt(); int d = io.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = io.nextInt();
		}
		Arrays.sort(arr);
		long ans = 1;
		int end = 0;
		for (int i = 0; i < n-1; i++) {
			while (end < n && arr[end]-arr[i] <= d) {
				end += 1;
			}
			ans = ((long)(ans * (end-i))) % MOD;
			
		}
		io.println(ans);
    }

    // Run
    public static void main(String[] args) throws IOException {
        Kattio io = new Kattio();
        solve(io);
        io.close();
    }
    
    // IO
	static class Kattio extends PrintWriter {
		private BufferedReader r;
		private StringTokenizer st;
		// standard input
		public Kattio() { this(System.in, System.out); }
		public Kattio(InputStream i, OutputStream o) {
			super(o);
			r = new BufferedReader(new InputStreamReader(i));
		}
		// USACO-style file input
		public Kattio(String problemName) throws IOException {
			super(problemName + ".out");
			r = new BufferedReader(new FileReader(problemName + ".in"));
		}
		// returns null if no more input
		public String next() {
			try {
				while (st == null || !st.hasMoreTokens())
					st = new StringTokenizer(r.readLine());
				return st.nextToken();
			} catch (Exception e) { }
			return null;
		}
		public int nextInt() { return Integer.parseInt(next()); }
		public double nextDouble() { return Double.parseDouble(next()); }
		public long nextLong() { return Long.parseLong(next()); }
	}
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 8732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 8384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 8308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 8216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 8132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 8168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 8572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 9296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 236 ms 16896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 19644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 630 ms 24416 KB Output is correct
2 Correct 601 ms 24324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 528 ms 36496 KB Output is correct
2 Correct 491 ms 36200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 547 ms 51996 KB Output is correct
2 Correct 603 ms 50660 KB Output is correct