Submission #713679

# Submission time Handle Problem Language Result Execution time Memory
713679 2023-03-22T19:41:17 Z hex A Huge Tower (CEOI10_tower) Java 11
Compilation error
0 ms 0 KB
import java.io.*;
import java.util.*;

public class Main {
	static final long MOD = (long) (1e9 + 9);

	public static void main (String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int N = Integer.parseInt(st.nextToken());
		int diff = Integer.parseInt(st.nextToken());
		int[] sizes = new int[N];
		st = new StringTokenizer(reader.readLine());
		for (int n = 0; n < N; n++) {
			sizes[n] = Integer.parseInt(st.nextToken());
		}
		int lt = 0;
		int rt = 0;
		long len;
		int ans = 1;
		while (lt < N) {
			while (rt < N - 1 && sizes[rt + 1] <= sizes[lt] + diff) rt++;
			len = rt - lt + 1;
			ans = (int) ((ans * len) % MOD);
			lt++;
		}
		out.println(ans);
		out.close();
	}
}
//Check N = 1.
//Check for needed longs.
//Use Long.parseLong() instead of Integer.parseInt().
//Use Long.MAX_VALUE instead of Integer.MAX_VALUE.
//Use an int array of ids instead of a boolean array of visited nodes during DFS.
//Declare a class variable instead of a method parameter, as passing by value could result in a TLE.

Compilation message

tower.java:4: error: class Main is public, should be declared in a file named Main.java
public class Main {
       ^
1 error