submatrix
Be there A
a matrix with n lines (numbered
from 1 to n)
and m columns (numbered from
1 to m)
with components from the set {0,
1}.
We call a coordinate (L1, C1, L2, C2) submatrix a rectangular area of the matrix that has the upper-left corner on line L1, column C1 and lower-right corner on line L2, column C2 (L1<=L2, C1<=C2).
The size of a submatrix is equal to the number of elements of the submatrix.
Task
Write a program that determines a maximum size submatrix comprised of only 1s.
Input Data
Input file submatrix.in
contains on the first line two positive integers n
and m, separated by a space.
Each of the following n lines
contain m digits of the set {0,
1}. Digits on the same line are
not separated by spaces.
Output Data
Output file submatrix.out
will contain on the first line the size of the determined submatrix (maximum
possible). The second line will contain 4
positive integers separated by a space, L1
C1 L2 C2, where (L1,C1)
represent the line and column of the upper-left corner of the determined submatrix
and (L2,C2)
represent the line and column of the lower-right corner of the submatrix. If
there is more than one solution available the solution for which the line of
the upper-left corner is minimal will be displayed. If there is still more than
one solution available the one for which the column of the upper-left corner
is minimal will be displayed. Finally, if there is still more than one solution
the one for which the line of the lower-right corner is minimal will be displayed.
Constraints
1 <= n, m <= 100
Examples
submatrix.in | submatrix.out | submatrix.in | submatrix.out |
4 5 11000 11100 01100 11110 |
6 2 2 4 3 |
3 7 0111100 1111100 1111010 |
8 1 2 2 5 |
Time limit: 0.5 seconds/test
prof. Emanuela Cerchez
"Grigore Moisil" Iaşi IT High School
Contact:emanuela.cerchez@gmail.com