Alien Virus
Time limit2sMemory limit1024 MB
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 cells vertically and 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 be the triangle formed by the centers of these cells. Suppose 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 passes through has a virus, then is called a virus structure. The number of grid cells that one side of 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 .
Input
The first line contains the vertical size and the horizontal size of the medium, separated by a space.
The next lines each contain a string of length made of 0 and 1. A 0 means the cell has no virus, and a 1 means the cell has a virus. For each and , if the -th character of line of the input is 1, the cell in row and column 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 .
Constraints
- All given numbers are integers.