eolymp
bolt
Try our new interface for solving problems
Problems

Zombie Blast!

Zombie Blast!

\includegraphics{https://static.e-olymp.com/content/19/19bb6abefb8ae1fd2dcae892d9ee5da9551257c7.jpg} Help!!! The zombies are marching! The zombie invasion has begun, and their legion is on the field, coming toward our last line of defense. All hope is not lost though. In anticipation of the forthcoming doom, you have deployed a host of Adjustable Conflagration Mines (ACMs) on the battlefield. You can detonate all these mines simultaneously to a single, blast radius you control, and each mine will instantaneously incinerate any zombie within its blast radius. You take a satellite image to give you a map of the situation. The map is a rectangular region divided into square cells of unit side length. Each cell is either empty, occupied by a zombie (\textbf{Z}), or occupied by a mine (\textbf{M}). For example, it could look like this: A zombie will be incinerated by a mine if the distance between the center of the cell it occupies and the center of the mine's cell is less than or equal to the blast radius. In order to minimize collateral damage, you have to set off the mines with the smallest blast size that will still incinerate all the zombies. For a given invasion scenario, what exactly is that radius? \InputFile Input begins with a line containing a single integer \textbf{N}, the number of invasion scenarios (maps) for which you need to determine a blast radius. Each scenario begins with a line containing two space-separated integers, \textbf{w} and \textbf{h} (\textbf{1}\textit{ }≤\textit{ }\textbf{w}, \textbf{h} ≤ \textbf{2000}), indicating the width and height of the map. Then the map follows as \textbf{h} lines of text with \textbf{w} characters each, telling you what occupies each cell: \begin{itemize} \item '\textbf{Z}' denotes a zombie \item '\textbf{M}' denotes a mine \item '\textbf{.}' denotes an empty cell. \end{itemize} Every map will have at least one zombie (\textbf{Z}) and one mine (\textbf{M}) on it. \OutputFile For each invasion scenario, output on a single line a real number r, the smallest blast radius with you must set off the mines in order to incinerate all the zombies. Your output must be accurate to an error of no more than a factor of \textbf{10^\{-6\}} relative to the exact answer. (For example, if the correct answer is \textbf{50}, any answer between \textbf{49.99995} and \textbf{50.00005} will be accepted.)
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
4 3
M..Z
..ZZ
M..Z
5 4
.ZZ.M
Z.Z..
.Z.ZZ
Z.Z.Z
Output example #1
3.16227766
5
Source ACM ICPC North America - Pacific Northwest 2010