# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
532736 | Cubik65536 | A Huge Tower (CEOI10_tower) | Java | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.*;
import java.util.*;
public class Main {
private static final int MOD = (int) 1e9 + 9;
public static void main(String[] args) throws IOException {
Kattio io = new Kattio();
int n = io.nextInt();
int d = io.nextInt();
int[] blocks = new int[n];
for (int i = 0; i < n; i++) {
blocks[i] = io.nextInt();
}
Arrays.sort(blocks);
int result = 1;
for (int i = 0, j = 0; i < n; i++) {
while (j < n - 1 && blocks[j + 1] - blocks[i] <= d) {
j++;
}
int dist = j - i + 1;
result = (int) (result * 1L * dist) % MOD;
}
io.println(result);
io.close();
}
}
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(new FileWriter(problemName + ".out"));
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// read next line
public String readLine() {
try {
return r.readLine();
} catch (IOException e) {
}
return null;
}
// 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());
}
}