Submission #391082

# Submission time Handle Problem Language Result Execution time Memory
391082 2021-04-17T19:31:46 Z yu_lim A Huge Tower (CEOI10_tower) Java 11
100 / 100
716 ms 45364 KB
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 p = 0; // previous
		for (int i = 1; i < N; i++) {
			while (p < i && blocks[p] + D < blocks[i])
				p++;
			// # of blocks <= i that can't stack on i
			towers[i] = (((i-p+1)) * towers[i - 1]) % M;
		}
		System.out.println(towers[N - 1] % M);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 77 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 8348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 8304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8360 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 109 ms 9484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 289 ms 17064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 19288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 716 ms 23544 KB Output is correct
2 Correct 716 ms 23120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 581 ms 33068 KB Output is correct
2 Correct 566 ms 32988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 644 ms 45364 KB Output is correct
2 Correct 707 ms 44772 KB Output is correct