시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB55452683.871%

문제

You love your new rain boots and want to keep them as clean as possible. Using satellite data you have gridded the area nearby as either muddy or not muddy. Write a program that will determine the fewest number of muddy puddles you must walk through to reach a destination.

Key:

  • ‘M’ – Muddy Puddle
  • ‘-’ – No Mud
  • ‘S’ – Start (No Mud)
  • ‘E’ – End (No Mud)

입력

There will be an unknown number of inputs. Each input will contain an 8 by 8 grid that represents the area nearby. There will be a single line containing a single ‘-‘ separating each input.

출력

For each input, display the fewest number of muddy puddles you must step through to reach the destination.

예제 입력 1

S-------
-M------
--M-----
---M----
----M-MM
-----M--
-----M--
-----ME-
-
SM------
MM------
--------
MMMMMMMM
--------
MMM-----
MEM-----
-----ME-
-
-------M
-MMMMM-M
-MS--M-M
-MMM-M-M
-----M-M
MMMMMM-M
-------M
EMMMMMMM
-
-M-MEM-M
M-M-M-M-
-M-M-M-M
M-M-M-M-
-M-M-M-M
M-M-M-M-
SM-M-M-M
M-M-M-M-

예제 출력 1

1
2
0
5