Problem B. Tempter of the Bone II
时间限制 5000 ms
内存限制 32 MB
The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze was changed and the way he came in was lost.He realized that the bone was a trap, and he tried desperately to get out of this maze.
The maze was a rectangle with the sizes of N by M. The maze is made up of a door,many walls and many explosives. Doggie need to reach the door to escape from the tempter. In every second, he could move one block to one of the upper, lower, left or right neighboring blocks. And if the destination is a wall, Doggie need another second explode and a explosive to explode it if he had some explosives. Once he entered a block with explosives,he can take away all of the explosives. Can the poor doggie survive? Please help him.
输入数据
输出数据
For each test case, print the minimum time the doggie need to escape if the doggie can survive, or -1 otherwise.
样例输入
复制
4 4
SX..
XX..
....
1..D
4 4
S.X1
....
..XX
..XD
0 0
样例输出
$ Mathjax font initiator $