#K65902. Count Submatrices With Target Sum
Count Submatrices With Target Sum
Count Submatrices With Target Sum
You are given a matrix with dimensions (n \times m) and an integer target sum (k). In addition, you are provided two integers (a) and (b) which specify the dimensions of a submatrix. Your task is to count the number of submatrices of size (a \times b) whose sum of elements is exactly (k).
A submatrix is defined as a contiguous block of cells within the original matrix. Consider every valid position where a submatrix of size (a \times b) can be placed and output the total count of those submatrices that add up to (k).
inputFormat
Input is read from standard input (stdin). The first line contains five space-separated integers: (n), (m), (k), (a) and (b), where (n) and (m) denote the number of rows and columns in the matrix, (k) is the target sum, and (a) and (b) are the dimensions of the submatrix. The next (n) lines each contain (m) space-separated integers representing the matrix.
outputFormat
Output a single integer to standard output (stdout): the number of submatrices of size (a \times b) whose elements sum up to (k).## sample
3 4 10 2 2
1 2 3 4
5 6 7 8
9 10 11 12
0