Problem list
Log in
#usaco0105 · USACO 2012-2013 US Open Gold

Figure Eight

Platinum I 2.0 s 256 MB

Farmer John's cows recently received a large piece of marble, which has a number of imperfections. We represent the piece of marble by an N by N square grid (5 <= N <= 300), where '*' represents an imperfection and '.' represents a flawless section.

The cows want to carve a number "8" in this piece of marble. A valid figure eight has these properties:

  • A figure eight consists of two rectangles, a top and a bottom.
  • Both the top and bottom have at least one cell in their interior.
  • The bottom edge of the top rectangle is a (not necessarily proper) subset of the top edge of the bottom rectangle.
  • The figure eight can only be carved from flawless regions of the piece of marble.

The aesthetic score of a figure eight is equal to the product of the areas enclosed by its two rectangles. The cows wish to maximize this score.

Input

  • Line 1: A single integer N, indicating the side length of the marble.
  • Lines 2..N+1: Each line describes a row of the marble, and contains N characters which are each either '*' (an imperfection) or '.' (a flawless section).

Output

The highest aesthetic score of any figure eight which doesn't use any imperfect squares of the marble. If no figure eight is attainable, output -1.

Example 1

Input
15
...............
...............
...*******.....
.*....*.......*
.*......*....*.
....*..........
...*...****....
...............
..**.*..*..*...
...*...**.*....
*..*...*.......
...............
.....*..*......
.........*.....
...............
Output
3888

Output details: The top rectangle has area 6x9=54 and the bottom 12x6=72, giving score 54x72=3888.

Source
USACO 2012-2013 US Open Gold
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code