eolymp
bolt
Try our new interface for solving problems
Problems

Spare the Ewoks!

Spare the Ewoks!

Rejuvenated after the successful siege of Cloud City, Emperor Palpatine has commissioned you to begin construction of a new Imperial base on the forest moon of Endor. Endor, however, is home to a species of cuddly creatures known as the 'Ewoks.' Having a soft spot in his otherwise callous heart for these Ewoks, Palpatine has ordered that none of the existing Ewok homes must be disturbed. Furthermore, he has asked that you make the base as large as possible in terms of total area, and that this area may be divided among up to three rectangular buildings. Help Palpatine in his quest for intergalactic domination! For this problem, you are provided a map of Endor in the form of an \textbf{m}×\textbf{n} rectangular grid, where some of the cells have been marked as Ewok homes, and other cells are empty. Your goal is to place up to three (but possibly fewer) rectangular buildings on this grid in such a way that no two buildings overlap with each other, and no building is placed over an Ewok home. \InputFile The input will contain multiple test cases. Each test case begins with a single line containing a pair of integers \textbf{m}and \textbf{n} (where \textbf{1} ≤ \textbf{m} ≤ \textbf{250} and \textbf{1} ≤ \textbf{n} ≤ \textbf{250}) representing the number of rows and columns in the grid. The next \textbf{m}lines then specify the map of Endor; specifically, each line will contain \textbf{n} characters, where each character is either '\textbf{.}' (a period) standing for an empty space, or '\textbf{e}' (lower case \textbf{E}) for an Ewok home. After the final test case will be a single line containing "\textbf{0 0}"; this line should not be processed. \OutputFile For each input test case, print a single integer indicating the maximum area that can be covered by buildings. \includegraphics{https://static.e-olymp.com/content/21/21eb888f28ec6a11e0ceabc2767aaad68d21c92a.jpg}
Time limit 3 seconds
Memory limit 256 MiB
Input example #1
1 2
..
5 6
eee...
ee...e
ee...e
e...ee
e..eee
8 12
eee...eee...
eee...eee...
ee...eee..ee
eee...eee...
ee...eee...e
eee..eee..ee
ee..eee..eee
eee..eee...e
0 0
Output example #1
2
13
22
Source ACM ICPC Regionals 2009: North America - Pacific Northwest