Submission #1122450

#TimeUsernameProblemLanguageResultExecution timeMemory
1122450uranium235A Huge Tower (CEOI10_tower)Java
100 / 100
644 ms86616 KiB
// package ojuz; import java.io.*; import java.util.*; public class tower { public static final long MODULO = (long) 1e9 + 9; public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] first = reader.readLine().split(" "); int n = Integer.parseInt(first[0]), d = Integer.parseInt(first[1]); int[] arr = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); Arrays.sort(arr); // for each block from largest to smallest, calculate how many blocks it can be on top of // within the margin d, each permutation of one block being on top of another defines // a unique tower, so just multiply all possibilities together long result = 1; int pointer = n - 1; for (int i = n - 1; i >= 0; i--) { while (pointer > 0 && arr[pointer - 1] + d >= arr[i]) pointer--; result = result * (i - pointer + 1) % MODULO; } System.out.println(result); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...