#P7365. Maximal I-Shaped Award Podium

    ID: 20563 Type: Default 1000ms 256MiB

Maximal I-Shaped Award Podium

Maximal I-Shaped Award Podium

YONG-IN Hall is represented by an n × m rectangular grid. Each sponsor’s display booth occupies one or more unit cells of the grid. An I-shaped award podium is built in the upright direction, with its edges parallel to the hall’s boundaries. It is constructed by stacking three rectangles vertically, where the top and bottom rectangles must extend further to both the left and right than the middle rectangle. In other words, if the middle rectangle spans columns \( [j_1, j_2] \) then for the top rectangle, if its horizontal span is \( [j_1-a, j_2+b] \) then both \( a \) and \( b \) must be at least 1, so that the middle rectangle is strictly "inscribed" in the top (and similarly, the bottom) rectangle. The three rectangles must be contiguous, meaning the bottom edge of the top rectangle touches the top edge of the middle rectangle, and the bottom edge of the middle touches the top edge of the bottom rectangle.

Your task is to find the I-shaped podium with the largest possible area such that it does not cover any display booths (obstacles) on the grid. A cell containing a display booth is marked with a '#' and an empty cell is marked with a '.'. If no valid I-shaped podium can be placed, output 0.

The three parts of the podium are defined as follows:

  • Middle rectangle: occupies rows \([i_1, i_2]\) and columns \([j_1, j_2]\), where \(0 \le i_1 \le i_2 < n\) and \(0 \le j_1 \le j_2 < m\). To allow room for the top and bottom parts, we require \(i_1 \ge 1\), \(i_2 \le n-2\), \(j_1 \ge 1\) and \(j_2 \le m-2\).
  • Top rectangle: directly above the middle rectangle, with height \(h_{top} \ge 1\) so that its rows are \([i_1-h_{top}, i_1-1]\), and horizontal span \([j_1-a, j_2+b]\) with \(a \ge 1, b \ge 1\) (and the indices within bounds).
  • Bottom rectangle: directly below the middle rectangle, with height \(h_{bot} \ge 1\) (its rows are \([i_2+1, i_2+h_{bot}]\)) and horizontal span \([j_1-c, j_2+d]\) with \(c \ge 1, d \ge 1\).

The overall area of the I-shaped podium is the sum of the areas of its three parts. Your goal is to compute the maximum area possible by choosing any valid configuration on a grid with obstacles. All cells covered by the podium must be free (i.e. contain a '.') for the podium to be valid.

Note on indices: The grid rows are numbered from 0 to \(n-1\) and columns from 0 to \(m-1\).

inputFormat

The input begins with two integers n and m (\(3 \le n, m \le 50\)), representing the number of rows and columns of the grid. The following n lines each contain a string of length m consisting of characters . (empty cell) or # (an obstacle, i.e. a display booth).

outputFormat

Output a single integer representing the maximum area of an I-shaped podium that can be placed without covering any obstacles. If no valid placement exists, output 0.

sample

5 5
.....
.....
.....
.....
.....
19