Letters
Given a matrix N x M. Each cell of the matrix contains some lowercase English letter.How many submatrices are there, that matches both following conditions:
• the submatrix contains at most K cells with letter L.
• all letters, located in all four corner cells of the submatrix, are equal.
Formally, a submatrix's definition is as follows. It is defined by four integers x1, y1, x2, y2 such that 1 ≤ x1 < x2 ≤ n, 1 ≤ y1 < y2 ≤ m. Then the submatrix contains all such cells (x, y) (x is the row number, y is the column number), for which the following inequality holds x1 ≤ x ≤ x2, y1 ≤ y ≤ y2. The corner cells of the matrix are cells (x1, y1), (x1, y2), (x2, y1), (x2, y2).
The first line contains three integers and one letter, N, M, K, L
2 <= N <= 400
2 <= M <= 400
0 <= K <= N * M
‘a’ <= L <= ‘z’
Next N lines contain M characters each.
Print a single integer — the number of required submatrices.
3 4 4 a
aabb
baab
baabOutput:
25 4 13 a
cbbb
bbbb
cccb
ccbc
bcbbOutput:
8Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.