Fort Moo
Time limit2sMemory limit512 MB
Find the largest interior area of a grid rectangle whose border cells are all grass, with swamp allowed inside.
- Level
Medium6 of 10
- Topics
- Prefix sum, Brute force, Matrix
- Solved
- No attempts yet
Problem
Bessie is building a fort with her friend Elsie. Like any good fort, this one starts with a sturdy frame. Bessie wants to build the frame as a rectangular outline one meter wide, and then raise the fort on top of it.
She has already picked the site, a piece of land meters by meters with . Parts of the site are swampy and cannot support the frame. Find the largest area Bessie can cover with her fort, meaning the area of the rectangle that the frame encloses, when the frame sits on no swampy cell.
The rectangle can be as small as . Only the cells on the outline have to be grass, and the cells inside may be swampy.
Input
The first line contains the integers and .
Each of the next lines contains characters describing the site. A '.' is normal grass and an 'X' is a swampy spot.
Output
Print one integer, the maximum area Bessie can cover with her fort. Print 0 if the frame fits nowhere.
Hint
In the first example the optimal frame is marked with 'f'.
.ffff.
.fX.fX
Xf.Xf.
.ffff.
..X...