(The original statement in Catalan has many private jokes. This English version goes straight to the point of the problem.)
Write a program to search for someone called “the telecos” on a given rectangular grid.
Input has several cases. Each case begins with two numbers
and
between 1 and 100. Follow
lines with
characters each: a dot indicates a free cell, a ‘P’
indicates a person, a ‘#’ indicates a wall, and a
‘T’ indicates the telecos. The search must always begin
from the upper-left cell (which never has a wall), and there is at most
one telecos on the grid.
For every case, if it is possible to reach the telecos, print the minimum number of steps to do so, and also the maximum number of persons that can be met in a path to the telecos with the minimum lenght. You can make horizontal and vertical movements, never leaving the grid. If the telecos is not in the grid, or if he is not reachable, tell so.
Input
1 4 .... 2 2 .. .T 2 2 .P .T 2 2 .. PT 2 2 .# #T 4 6 P#TPPP .#.PPP .#PPPP ...PPP 1 1 T
Output
The telecos ran away. 2 0 2 1 2 1 The telecos is hidden. 8 2 0 0