Submission #260716

# Submission time Handle Problem Language Result Execution time Memory
260716 2020-08-10T19:07:59 Z idk321 Rectangles (IOI19_rect) Java 11
0 / 100
2719 ms 1048580 KB
import java.util.Arrays;

class rect {
	boolean[][] visited;

	public long count_rectangles(int[][] a) {
		int n = a.length;
		int m = a[0].length;
		int[][] dpUp = new int[n][m];
		int[][] dpDown = new int[n][m];
		int[][] dpLeft = new int[n][m];
		int[][] dpRight = new int[n][m];

		for (int i = 1; i < n - 1; i++) {
			for (int j = m - 2; j > 0; j--) {
				if (a[i - 1][j] > a[i][j]) dpUp[i][j] = dpUp[i][j + 1] + 1;
				if (a[i + 1][j] > a[i][j]) dpDown[i][j] = dpDown[i][j + 1] + 1;
			}
		}
		for (int i = n - 2; i > 0; i--) {
			for (int j = 1; j < m - 1; j++) {
				if (a[i][j + 1] > a[i][j]) dpRight[i][j] = dpRight[i + 1][j] + 1;
				if (a[i][j - 1] > a[i][j]) dpLeft[i][j] = dpLeft[i + 1][j] + 1;
			}
		}

		if (n <= 2 || m <= 2) return 0;

		boolean allZeroAndOne = true;
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (a[i][j] != 0 && a[i][j] != 1) allZeroAndOne = false;

		if (n <= 3) {
			int currLength = 0;
			int goodStarts = 0;
			long res = 0;
			for (int i = 1; i < m - 1; i++) {
				int h = a[1][i];
				if (a[0][i] <= h || a[2][i] <= h) {
					goodStarts = 0;
				} else {
					if (a[1][i - 1] > h) goodStarts++;
					if (a[1][i + 1] > h) res += goodStarts;
				}
			}

			return res;
		/*} else if (allZeroAndOne) {
			visited = new boolean[n][m];
			Arrays.fill(visited[0], true);
			Arrays.fill(visited[n - 1], true);
			for (int i = 0; i < n; i++) {
				visited[i][0] = true;
				visited[i][m - 1] = true;
			}
			for (int i = 1; i < n - 1; i++) {
				for (int j = 1; j < m - 1; j++) {

				}
			} */
		} else {
			int[][][] maxRight = new int[n][m][m];
			for (int i = 1; i < n - 1; i++) {
				for (int j = 1; j < m - 1; j++) {
					for (int k = j; k < m - 1; k++) {
						if (j == k) {
							maxRight[i][j][k] = a[i][j];
						} else {
							maxRight[i][j][k] = Math.max(a[i][k], maxRight[i][j][k - 1]);
						}
					}
				}
			}
			boolean[][][][] rightOk = new boolean[n][n][m][m];
			for (int i = 1; i < n - 1; i++) {
				for (int k = 1; k < n - 1; k++) {
					for (int j = 1;  j < m - 1; j++) {
						for (int l = 1; l < m - 1; l++) {
							rightOk[i][k][j][l] = maxRight[k][j][l] < a[k][l + 1];
							if (k != i) {
								rightOk[i][k][j][l] = rightOk[i][k][j][l] && rightOk[i][k - 1][j][l];
							}
						}
					}
				}
			}

			int[][][] maxDown = new int[m][n][n];
			for (int j = 1; j < m - 1; j++) {
				for (int i = 1; i < n - 1; i++) {
					for (int k = j; k < n - 1; k++) {
						if (i == k) {
							maxDown[j][i][k] = a[i][j];
						} else {
							maxDown[j][i][k] = Math.max(a[k][j], maxDown[j][i][k - 1]);
						}
					}
				}
			}

			long rect = 0;
			for (int i = 1; i < n - 1; i++) {
				for (int j = 1; j < m - 1; j++) {
					for (int k = i; k < n - 1; k++) {
						if (a[k][j - 1] <= a[k][j]) break;
						for (int l = j; l < m - 1; l++) {
							if (a[i - 1][l] <= a[i][l]) break;
							if (maxDown[l][i][k] >= a[k + 1][l]) break;
							if (rightOk[i][k][j][l]) {
								rect++;
								//System.out.println(i + " " + j + " " + k + " " + l);
							}
						}
					}
				}
			}

			return rect;
		}
	}


}
# Verdict Execution time Memory Grader output
1 Correct 78 ms 10336 KB Output is correct
2 Incorrect 116 ms 13204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 10336 KB Output is correct
2 Incorrect 116 ms 13204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 10336 KB Output is correct
2 Incorrect 116 ms 13204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 10336 KB Output is correct
2 Incorrect 116 ms 13204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 96 ms 11044 KB Output is correct
2 Correct 118 ms 10800 KB Output is correct
3 Correct 89 ms 10796 KB Output is correct
4 Correct 79 ms 10220 KB Output is correct
5 Incorrect 99 ms 10872 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 92 ms 10212 KB Output is correct
2 Runtime error 2719 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 10336 KB Output is correct
2 Incorrect 116 ms 13204 KB Output isn't correct
3 Halted 0 ms 0 KB -