Run-up Jump
Time limit2sMemory limit1024 MB
Given a grid with traps, decide whether repeated run-up and long jump moves can carry the start cell S to the end cell E.
- Level
Medium6 of 10
- Topics
- Graph, BFS, Simulation
- Solved
- No attempts yet
Problem
A grid has rows and columns. Each cell is either an empty cell or a trap. On this grid, a jump consists of a run-up followed by a long jump, in that order.
- (Run-up) Choose an integer , pick one of the four directions (up, down, left, right) from the current cell, and move one cell at a time times in that direction. The moves must not enter a trap cell or leave the grid.
- (Long jump) Then choose an integer with , and jump cells in the same direction. The landing cell must not be a trap and must lie inside the grid.
Starting from the start cell, determine whether you can reach the end cell after any number of jumps.
Input
The first line contains the number of test cases ().
Each test case follows.
The first line contains two integers and ().
Each of the next lines contains a string of length that describes one row of the grid. Each character is one of ., #, S, or E, with these meanings:
.: empty cell#: trapS: start cellE: end cell
Each test case contains exactly one S and exactly one E.
The sum of over all test cases is at most .
Output
For each test case, print one line. Print YES if you can reach the cell marked E, and NO otherwise.