Problem BT
Treasure Hunt

You are a treasure hunter searching for gold in the wild. Luckily you got a map of the area from a black marketeer. The map clearly shows where a box of gold is along with the surrounding terrain. Of course, you want to head to the treasure as fast as possible. However, the trip might not be easy.
The area is described by a grid of
At the beginning of your trip you have
Plan wisely with the map and determine the minimum number of days you need to reach the treasure.
Input
The first line has three integers
Output
Output the minimum number of days you need to reach the treasure. If it is impossible to get to the treasure, output “-1”.
Sample Input 1 | Sample Output 1 |
---|---|
2 5 4 S#.F. .MFMG |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
1 2 1 GS |
1 |
Sample Input 3 | Sample Output 3 |
---|---|
2 2 10 S# #G |
-1 |
Sample Input 4 | Sample Output 4 |
---|---|
1 7 4 SMMMMMG |
5 |