Submission #685825

# Submission time Handle Problem Language Result Execution time Memory
685825 2023-01-25T01:48:23 Z bruhgamer A Huge Tower (CEOI10_tower) Java 11
100 / 100
590 ms 55492 KB
//package USACO;
import java.util.*;
import java.io.*;
public class tower {
	public static void main(String[]args) throws IOException{
		Kattio io = new Kattio();
		int n = io.nextInt();
		int d = io.nextInt();
		int[]arr = new int[n];
		int[]valuesless = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = io.nextInt();
		}
		Arrays.sort(arr);
		int j = 0;
		for(int i = 1; i < n; i++) {
			while(arr[i] - arr[j] > d) {
				j++;
			}
			valuesless[i]+=(i - j);
		}
		long[]values = new long[n];
		values[0] = 1;
		for(int i = 1; i < n ; i++) {
			values[i] = (values[i-1] * (valuesless[i] + 1)) % 1000000009L;
		}
		io.println(values[n-1]);
		io.close();
	}
	static class Kattio extends PrintWriter {
		private BufferedReader r;
		private StringTokenizer st;
		// standard input
		public Kattio() { this(System.in, System.out); }
		public Kattio(InputStream i, OutputStream o) {
			super(o);
			r = new BufferedReader(new InputStreamReader(i));
		}
		// USACO-style file input
		public Kattio(String problemName) throws IOException {
			super(problemName + ".out");
			r = new BufferedReader(new FileReader(problemName + ".in"));
		}
		// returns null if no more input
		public String next() {
			try {
				while (st == null || !st.hasMoreTokens())
					st = new StringTokenizer(r.readLine());
				return st.nextToken();
			} catch (Exception e) { }
			return null;
		}
		public int nextInt() { return Integer.parseInt(next()); }
		public double nextDouble() { return Double.parseDouble(next()); }
		public long nextLong() { return Long.parseLong(next()); }
	}
		
}
# Verdict Execution time Memory Grader output
1 Correct 57 ms 8392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 8532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 8368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 8384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 8216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 8400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 8220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 8308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 8336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 8288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 8168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 9252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 17124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 296 ms 19640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 590 ms 24096 KB Output is correct
2 Correct 580 ms 23840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 33736 KB Output is correct
2 Correct 454 ms 33752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 515 ms 50652 KB Output is correct
2 Correct 575 ms 55492 KB Output is correct