# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
713679 | hex | 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 {
static final long MOD = (long) (1e9 + 9);
public static void main (String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(reader.readLine());
int N = Integer.parseInt(st.nextToken());
int diff = Integer.parseInt(st.nextToken());
int[] sizes = new int[N];
st = new StringTokenizer(reader.readLine());
for (int n = 0; n < N; n++) {
sizes[n] = Integer.parseInt(st.nextToken());
}
int lt = 0;
int rt = 0;
long len;
int ans = 1;
while (lt < N) {
while (rt < N - 1 && sizes[rt + 1] <= sizes[lt] + diff) rt++;
len = rt - lt + 1;
ans = (int) ((ans * len) % MOD);
lt++;
}
out.println(ans);
out.close();
}
}
//Check N = 1.
//Check for needed longs.
//Use Long.parseLong() instead of Integer.parseInt().
//Use Long.MAX_VALUE instead of Integer.MAX_VALUE.
//Use an int array of ids instead of a boolean array of visited nodes during DFS.
//Declare a class variable instead of a method parameter, as passing by value could result in a TLE.