Submission #385757

# Submission time Handle Problem Language Result Execution time Memory
385757 2021-04-04T21:55:02 Z dapig Calvinball championship (CEOI15_teams) Java 11
10 / 100
1000 ms 65536 KB
//package week4;

import java.io.*;
import java.util.*;

class teams {

	public static void main(String[] args) throws IOException {

		teams obj = new teams();

		obj.doStuff();

	}
	
	int process(int pos, int val, int max) {
		if (val == 1) return 0;
		if (pos == vals.length-1) return val-1;
		int[][] grid = new int[vals.length-pos-1][vals.length-pos+1];
		grid[0][1] = val-1;
		grid[0][0] = max*(val-1)%1000007;
		grid[0][0] = (grid[0][0]+grid[0][1])%1000007;
		for (int i = 1; i < grid.length; i++) {
			for (int j = i+1; j > 0; j--) {
				grid[i][j] = grid[i-1][j-1];
				grid[i][j] += grid[i][j+1];
				grid[i][j] %= 1000007;
			}
			grid[i][0] = grid[i-1][0];
			grid[i][0] += grid[i][1];
			grid[i][0] %= 1000007;
		}
		return grid[grid.length-1][0];
	}

	int[][] grid; // [pos] [number of valid ways if at cur pos and max val is #]
	int[] vals;
	private void doStuff() throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int len = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		vals = new int[len];
		for (int i = 0; i < vals.length; i++) {
			vals[i] = Integer.parseInt(st.nextToken());
		}
		br.close();

		grid = new int[vals.length][vals.length+1];
		Arrays.fill(grid[grid.length-1], 1);
		grid[grid.length-1][0] = 0;
		for (int i = 1; i < grid[0].length; i++) {
			grid[grid.length-1][i] += grid[grid.length-1][i-1];
		}
		for (int i = grid.length-2; i >= 0; i--) {
			for (int j = 1; j <= i+1; j++) {
				grid[i][j] = (grid[i+1][j+1]+grid[i][j-1])%1000007;
			}
		}
		int ans = 1;
		int max = 1;
		int max2 = 1;
		for (int i = 0; i < vals.length; i++) {
			if (vals[i] > max) {
				max2 = max;
				max = vals[i];
			} else if (vals[i] > max2) max2 = vals[i];
			ans += process(i, vals[i], max2);
			ans %= 1000007;
		}
		System.out.println(ans);

	}

}
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8556 KB Output is correct
2 Correct 71 ms 8428 KB Output is correct
3 Correct 72 ms 8424 KB Output is correct
4 Correct 74 ms 8812 KB Output is correct
5 Correct 73 ms 8556 KB Output is correct
6 Correct 73 ms 8768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8372 KB Output is correct
2 Incorrect 73 ms 8524 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 8424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 11052 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 10588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 302 ms 17880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 31024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 279 ms 65536 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 179 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 290 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -