#P4858. Maximum Cover Rectangle
Maximum Cover Rectangle
Maximum Cover Rectangle
Given an \(n \times m\) grid with each cell being either X
or _
, select a rectangle of size \(r \times c\) with the maximum area such that it is possible to cover every cell marked X
by one or more placements (placements are allowed to overlap) of this \(r \times c\) rectangle. Each placement of the rectangle must lie completely within cells marked X
(i.e. it must not cover any cell marked _
). The task is to find the dimensions \(r\) and \(c\) of such a rectangle with maximum area (i.e. maximize \(r \times c\)).
More formally, let the grid be given as a matrix \(G\) where \(G_{ij} \in \{X,\_\}\). A candidate rectangle of size \(r \times c\) is valid if for every cell \((i,j)\) with \(G_{ij} = X\), there exists some placement of the \(r \times c\) rectangle such that:
[ \text{(a)} ; \text{The rectangle is entirely placed within the grid.}] [ \text{(b)} ; The placed rectangle covers ((i,j)) and every cell inside the rectangle is (X).]
You need to choose the rectangle with maximum \(r \times c\) that satisfies the above condition. If there are multiple such rectangles with the same maximum area, any one is acceptable.
inputFormat
The first line contains two integers \(n\) and \(m\) (\(1 \leq n, m \leq 50\)), representing the number of rows and columns of the grid. Each of the next \(n\) lines contains a string of length \(m\) consisting only of characters X
and _
.
outputFormat
Output two integers \(r\) and \(c\) representing the dimensions of the chosen rectangle. The rectangle must have the maximum area among all rectangles that satisfy the covering condition.
sample
3 3
XXX
XXX
XXX
3 3
</p>