import java.util.*;
import java.io.*;
public class tower {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer str = new StringTokenizer(br.readLine());
int N = Integer.parseInt(str.nextToken());
int D = Integer.parseInt(str.nextToken());
int M = 1_000_000_009;
int[] blocks = new int[N];
str = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++)
blocks[i] = Integer.parseInt(str.nextToken());
br.close();
Arrays.sort(blocks);
long[] towers = new long[N];
towers[0] = 1;
int prev = 0;
for (int i = 0; i < N; i++) {
while (prev < i) {
if (blocks[prev] + D < blocks[i])
prev++;
else
break;
}
// # of blocks <= i that can't stack on i
if (i > 0)
towers[i] = (((i - prev + 1) % M) * towers[i - 1]) % M;
}
System.out.println(towers[N - 1] % M);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
8524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
8244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
8416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
8488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
8204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
8496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
8340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
9284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
17092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
361 ms |
19376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
711 ms |
23548 KB |
Output is correct |
2 |
Correct |
704 ms |
23152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
585 ms |
32984 KB |
Output is correct |
2 |
Correct |
558 ms |
33132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
637 ms |
45440 KB |
Output is correct |
2 |
Correct |
708 ms |
44988 KB |
Output is correct |