Baby Shark 2
InterviewTime limit2sMemory limit512 MB
Given an N by M grid with some cells holding sharks, find the empty cell whose Chebyshev distance to the nearest shark is largest.
- Level
Medium4 of 10
- Topics
- BFS, Graph, Brute force, Implementation
- Solved
- No attempts yet
Problem
In a space of size there are several baby sharks. The space is divided into square cells of size . Each cell contains at most one baby shark.
The safety distance of a cell is the distance from that cell to the nearest baby shark. The distance between two cells is the number of cells that must be passed through to get from one cell to the other, and movement is possible in the 8 adjacent directions (including diagonals).
Find the cell with the greatest safety distance.
Input
The first line gives the size of the space, and (). From the second line, lines give the state of the space, where 0 is an empty cell and 1 is a cell containing a baby shark. Only inputs with at least one empty cell and at least one shark are given.
Output
Print the maximum safety distance on the first line.