Submission #343919

#TimeUsernameProblemLanguageResultExecution timeMemory
343919skuradaA Huge Tower (CEOI10_tower)Java
100 / 100
753 ms50904 KiB
import java.util.*; import java.io.*; public class tower { static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public float nextFloat() { return Float.parseFloat(next()); } public double nextDouble() { return Float.parseFloat(next()); } public long nextLong() { return Long.parseLong(next()); } } static class CPMath { static int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } static int sub(int a, int b) { a -= b; if (a < 0) a += mod; return a; } static int multiply(int a, long b) { b = a * b; return (int) (b % mod); } static int divide(int a, int b) { return multiply(a, inverse(b)); } static int inverse(int a) { return power(a, mod - 2); } static int power(int a, int b) { int r = 1; while (b > 0) { if (b % 2 == 1) { r = multiply(r, a); } a = multiply(a, a); b /= 2; } return r; } } static InputReader sc; static PrintWriter pw; static int mod = (int) (1e9 + 9); public static void main(String[] args) throws Exception { sc = new InputReader(System.in); pw = new PrintWriter(System.out); int n = sc.nextInt(); int d = sc.nextInt(); int[] towers = new int[n]; for (int i = 0; i < n; i++) { towers[i] = sc.nextInt(); } Arrays.sort(towers); int left_pointer = n-1; int result = 1; for (int i = n-1; i >= 0; i--) { while (left_pointer - 1 >= 0 && towers[left_pointer - 1] + d >= towers[i]) { left_pointer--; } result = CPMath.multiply(result, i - left_pointer + 1); } pw.println(result); pw.close(); } }
#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...