# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
740773 | 2023-05-13T05:32:21 Z | yeroc | A Huge Tower (CEOI10_tower) | Java 11 | 0 ms | 0 KB |
// File: HugeTower.java // Date: 04/15/2023 // Author: Corey Zhu 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()); } } }