Submission #391080

# Submission time Handle Problem Language Result Execution time Memory
391080 2021-04-17T19:29:56 Z yu_lim A Huge Tower (CEOI10_tower) Java 11
100 / 100
719 ms 45368 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 = 0; i < N; i++) {
			while (p < i && blocks[p] + D < blocks[i])
				p++;
			// # of blocks <= i that can't stack on i
			if (i > 0)
				towers[i] = (((i-p+1)) * towers[i - 1]) % M;
		}
		System.out.println(towers[N - 1] % M);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 8328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 9240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 288 ms 17208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 19180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 719 ms 23612 KB Output is correct
2 Correct 705 ms 23332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 588 ms 33048 KB Output is correct
2 Correct 562 ms 33000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 645 ms 45368 KB Output is correct
2 Correct 698 ms 44844 KB Output is correct