Submission #685829

# Submission time Handle Problem Language Result Execution time Memory
685829 2023-01-25T01:50:24 Z bruhgamer A Huge Tower (CEOI10_tower) Java 11
100 / 100
623 ms 50508 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);
		long[]values = new long[n];
		values[0] = 1;
		int j = 0;
		for(int i = 1; i < n; i++) {
			while(arr[i] - arr[j] > d) {
				j++;
			}
			valuesless[i]+=(i - j);
			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 75 ms 8360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 8304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 8412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 8116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 9112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 260 ms 16952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 324 ms 19696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 623 ms 24008 KB Output is correct
2 Correct 622 ms 24180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 534 ms 33744 KB Output is correct
2 Correct 472 ms 33700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 537 ms 50508 KB Output is correct
2 Correct 577 ms 50000 KB Output is correct