Under construction

Still being built. Things may change

Figure Eight

Time limit1sMemory limit128 MB

Summary
Find two axis-aligned rectangles sharing one horizontal edge row, outlines all flawless, maximizing the product of the two interior areas.
Level

Hard8 of 10

Topics
Prefix sum, Implementation, Brute force, Greedy
Solved
No attempts yet

Problem

Farmer John's cows received a large square slab of marble that, unfortunately, has a few imperfections. The slab is an N×NN \times N grid (5≤N≤3005 \le N \le 300) where * marks an imperfection and . marks a flawless cell.

The cows love the number 8 (with a cloven hoof on each of their four feet they can count to eight on their "toes"), so they want to carve a figure eight into the slab. A figure eight is drawn from the outlines of two axis-aligned rectangles — a top rectangle and a bottom rectangle — that satisfy all of the following:

  • Each rectangle encloses at least one interior cell.
  • The two rectangles share a single horizontal line: the bottom edge of the top rectangle lies on the top edge of the bottom rectangle and is a (not necessarily proper) sub-segment of it. In other words, both edges sit on the same row, and the top rectangle's left and right columns lie between the bottom rectangle's left and right columns, endpoints included.
  • Every cell along the outline (all four sides of both rectangles) must be flawless (.). Interior cells are unrestricted and may contain imperfections.

A rectangle spanning rows a..ba..b and columns c..dc..d encloses an interior area of (b−a−1)×(d−c−1)(b - a - 1)\times(d - c - 1). The aesthetic score of a figure eight is the product of its two enclosed interior areas, and the cows want it as large as possible.

Schematic of one figure eight (8 marks the carved outline cells):

.8888...
.8..8...
88888888
8......8
88888888

Report the maximum achievable aesthetic score, or -1 if no valid figure eight can be carved.

Input

  • Line 1: a single integer NN, the side length of the slab.
  • Lines 2…N+12 \ldots N+1: each line has NN characters, each either * (an imperfection) or . (a flawless cell), describing one row of the marble.

Output

  • A single line: the highest aesthetic score of any figure eight whose outline uses no imperfect cells. If no figure eight is attainable, output -1.

Examples2

  1. Example 1

    Input
    15
    ...............
    ...............
    ...*******.....
    .*....*.......*
    .*......*....*.
    ....*..........
    ...*...****....
    ...............
    ..**.*..*..*...
    ...*...**.*....
    *..*...*.......
    ...............
    .....*..*......
    .........*.....
    ...............
    
    Expected output
    3888
    
  2. Example 2

    Input
    5
    .....
    .....
    .....
    .....
    .....
    
    Expected output
    9