You are given an
grid. Some cells, marked with ‘#’, have a wall. The rest of
cells are free, and they are marked with ‘.’. There are two
exceptions: one free cell is marked with ‘S’ (it is your
starting position), and another free cell is marked with
‘T’ (it has a treasure).
Your goal is to reach the treasure as fast as possible. Every second, you can either move to an adjancent free cell, or hit an adjancent wall with a hammer. You know that every wall vanishes after hits.
Input consists of several cases, each with , and , followed by lines with characters each. Assume that and are between 1 and 1000, and that is between 1 and .
For every case, print the minimum time to reach the treasure from the starting position.
Author: Pol Mauri
Generation: 2026-01-25T12:03:32.470Z
© Jutge.org, 2006–2026.
https://jutge.org