Square
InterviewTime limit2.5sMemory limit1024 MB
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 rows and 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 and separated by a space. The next lines each contain 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