Submission #391078

# Submission time Handle Problem Language Result Execution time Memory
391078 2021-04-17T19:27:57 Z yu_lim A Huge Tower (CEOI10_tower) Java 11
100 / 100
720 ms 45380 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) {
				if (blocks[p] + D < blocks[i])
					p++;
				else
					break;
			}
			// # 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 71 ms 8564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 8464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8352 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 73 ms 8156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 8472 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 72 ms 8380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 9360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 286 ms 16952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 355 ms 19152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 720 ms 23408 KB Output is correct
2 Correct 706 ms 23216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 589 ms 33280 KB Output is correct
2 Correct 549 ms 33152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 639 ms 45380 KB Output is correct
2 Correct 704 ms 44960 KB Output is correct