Submission #735263

# Submission time Handle Problem Language Result Execution time Memory
735263 2023-05-03T19:25:40 Z dxf A Huge Tower (CEOI10_tower) Java 11
100 / 100
674 ms 50640 KB
// Source: https://usaco.guide/general/io

import java.io.*;
import java.util.*;

public class tower {
	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st = new StringTokenizer(r.readLine());
		int n = Integer.parseInt(st.nextToken());
		int d = Integer.parseInt(st.nextToken());
		
		int[] sizes = new int[n];
		st = new StringTokenizer(r.readLine());
		for (int i = 0; i < n; i++) {
			sizes[i] = Integer.parseInt(st.nextToken());
		}
		long former = 1;
		Arrays.sort(sizes);
		int loc = 0;
		for (int i = 0; i < n; i++) {
			while (loc < n-1 && sizes[loc+1]-sizes[i] <= d) {
				loc ++;
			}
			int dist = loc-i+1;
			former = (((long) former) * dist) % 1000000009;
		}
	
		
		System.out.println(former);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 62 ms 8204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 8160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 8228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 8240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 9284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 250 ms 16896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 315 ms 19392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 674 ms 23840 KB Output is correct
2 Correct 607 ms 24188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 480 ms 33616 KB Output is correct
2 Correct 476 ms 36128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 559 ms 45832 KB Output is correct
2 Correct 596 ms 50640 KB Output is correct