This page is still under construction.

Parts of this page are still being built. What you see may change.

Square

Interview

Time limit2.5sMemory limit1024 MB

Summary
Given a table of 0s and 1s, find the largest odd side length of a square whose two diagonals contain only 1s.
Level

Medium5 of 10

Topics
Dynamic programming, Matrix, Implementation
Solved
No attempts yet

Problem

The table has mm rows and nn columns. It is made of identical small squares, and each square contains either 0 or 1. Consider a square whose sides are parallel to the rows and columns of the table and which is made of cells of the table. The side of the square must contain an odd number of cells, and both diagonals of the square must consist only of cells that contain 1. Write a program square that finds the maximum possible side length of such a square, measured in cells.

Input

The first line contains the values of nn and mm separated by a space. The next mm lines each contain nn digits. Each digit is 0 or 1, and the digits in each line are written without separators. The table contains at least one 1.

Output

A single integer, the maximum side length sought.

Constraints

2<m<30002 < m < 3000 2<n<30002 < n < 3000

Examples1

  1. Example 1

    Input
    10 8
    10111111
    11111111
    10111111
    11111110
    01111110
    11111110
    11111111
    10110111
    11111111
    11111111
    
    Expected output
    7