← 返回 meta 的题目列表Maze Solver: Add One-Way Chutes in BFS Pathfinding
类型:online_judge
Problem: Shortest Path in a Maze with One-Way Chutes (>)
You are given an R x C maze grid. Each cell is one of:
#: wall (blocked)
S: start
E: end
.: open cell
>: one-way chute/door
You can move in 4 directions (up/down/left/right).
One-way rule:
You may enter a > cell only from its left neighbor (i.e., the move must be left -> right).
After you are on a > cell, your next move is forced to go one step to the right into the cell immediately to its right (if out of bounds or a wall, the path dies).
Return the minimum number of steps from S to E, or -1 if unreachable.
Input
First line: R C
Next R lines: strings of length C
Output
Single integer: minimum steps or -1
Constraints
1 <= R, C <= 200
Example
Input
1 2
SE
Output
1