영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
Problem
You are playing mini-golf on an R × C grid. With one stroke, you can putt the golf ball any number of steps up to K straight in one of the four directions: up, down, right, or left. Of course, you cannot putt the ball through a wall or outside the course.
Your task is to calculate the minimum number of putts needed to get the ball into the hole.
Input
The first line contains three integers R, C, and K (1 ≤ R × C ≤ 10^6, 1 ≤ K ≤ 10^6), the number of rows, the number of columns, and the maximum distance you can putt.
The following R lines each contain a string with C characters, describing the mini-golf course:
- ”
.” means the cell is empty. - ”
#” means the cell has a wall in it. - ”
S” means this cell is your starting point. There will be exactly one ”S” in the input. - ”
G” means this cell has the hole. There will be exactly one ”G” in the input.
It is guaranteed that it is possible to reach the hole from the starting cell.
Output
Print an integer: the smallest number of putts needed to shoot the ball into the hole.
Points
Your solution will be tested on several test case groups. To get the points for a group, it must pass all the test cases in the group.
| Group | Point value | Constraints |
|---|---|---|
| 1 | 8 | There are no walls (”#”) in the input. |
| 2 | 18 | R = 2 |
| 3 | 22 | 1 ≤ R,C,K ≤ 100 |
| 4 | 25 | K ≥ max(R,C), in other words, you are not limited by how long you can putt. |
| 5 | 27 | No additional constraints. |
예제
예제 1
2 3 2 S.G ...
1
예제 2
2 5 1 S#... ...#G
7
예제 3
16 10 100 ..######.. .#......#. #...G....# #........# .#......#. ..#....#.. ..#....#.. ..###..#.. ..#....#.. ..#..###.. ..#....#.. ..###..#.. ..#....#.. ..#....#.. ..#.S..#.. ..######..
7