//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[][] 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;
for (int i = 0; i < vals.length; i++) {
ans += grid[i][vals[i]-1];
ans %= 1000007;
}
System.out.println(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
8808 KB |
Output is correct |
2 |
Correct |
85 ms |
8428 KB |
Output is correct |
3 |
Correct |
71 ms |
8556 KB |
Output is correct |
4 |
Correct |
71 ms |
8528 KB |
Output is correct |
5 |
Correct |
70 ms |
8548 KB |
Output is correct |
6 |
Correct |
72 ms |
8552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
8556 KB |
Output is correct |
2 |
Incorrect |
72 ms |
8320 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
8668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
8532 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
8460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
103 ms |
10604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
111 ms |
15580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
304 ms |
65536 KB |
Execution killed with signal 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
181 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
318 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |