Under construction

Still being built. Things may change

Alien Virus

Time limit2sMemory limit1024 MB

Summary
Given a grid of 0s and 1s, find the largest axis-aligned right isosceles triangle whose boundary cells all contain 1, measured by the cell count of one leg.
Level

Medium6 of 10

Topics
Matrix, Brute force, Implementation
Solved
No attempts yet

Problem

Ian visited Iapetus, a moon of Saturn, during a trip to Saturn a while ago. While analyzing a soil sample he collected there, he found an alien virus. The virus grew very well on a flat grid-shaped medium. The medium has HH cells vertically and WW cells horizontally, and every cell is a square of the same size. The virus could bind horizontally and vertically. When several viruses were placed in the shape of right isosceles triangles whose legs are horizontal and vertical, they formed a large structure. Ian defined a virus structure as follows.

  • Take three distinct grid cells. Let TT be the triangle formed by the centers of these cells. Suppose TT is a right isosceles triangle and its legs, the sides that are not the hypotenuse, are parallel to the vertical or horizontal direction of the medium. If every grid cell that the boundary of TT passes through has a virus, then TT is called a virus structure. The number of grid cells that one side of TT passes through is the size of this virus structure.

Given whether each cell of the medium has a virus, find the maximum size over all virus structures. If no virus structure exists, output 00.

Input

The first line contains the vertical size HH and the horizontal size WW of the medium, separated by a space.

The next HH lines each contain a string of length WW made of 0 and 1. A 0 means the cell has no virus, and a 1 means the cell has a virus. For each 1≤i≤H1\leq i\leq H and 1≤j≤W1\leq j\leq W, if the jj-th character of line 1+i1+i of the input is 1, the cell in row ii and column jj of the medium has a virus. If it is 0, the cell has no virus.

Output

Print one integer, the maximum size of a virus structure. If no virus structure exists, print 00.

Constraints

  • 1≤H≤7501 \le H \le 750
  • 1≤W≤7501 \le W \le 750
  • All given numbers are integers.

Examples3

  1. Example 1

    Input
    5 5
    11111
    10010
    10100
    11001
    10001
    
    Expected output
    5
    
  2. Example 2

    Input
    5 7
    1111111
    1111010
    1101000
    0111000
    1100000
    
    Expected output
    3
    
  3. Example 3

    Input
    3 3
    101
    010
    101
    
    Expected output
    0