Infiltration
Time limit1sMemory limit1024 MB
Decide whether Choi can walk from (1, 1) to (N, M) without touching a laser or being caught by a robot that follows one second behind.
- Level
Medium7 of 10
- Topics
- BFS, Graph, Implementation
- Solved
- No attempts yet
Problem
On a dark night, Corporal Choi, an infiltration specialist, is carrying out a secret operation to sneak into an enemy base and steal their secrets.
The enemy base is a two-dimensional grid with rows and columns. Choi starts at the entrance and must move to the target . Every second, Choi moves one cell up, down, left, or right, or stays in place.
Laser sensors are installed in the base to detect intruders. Each sensor is placed on the boundary between two adjacent rows and fires a laser to the left or to the right. A laser keeps extending until it reaches a wall or another laser sensor. At most 2 sensors can be installed on the same boundary. If Choi touches a fired laser or steps on a sensor, Choi is detected and the operation fails.
1 second after Choi enters at the entrance, an autonomous security robot follows Choi into the entrance. Like Choi, the robot moves one cell up, down, left, or right, or stays in place every second. Unlike Choi, the robot is unaffected when it touches a laser sensor while moving. If the robot and Choi are in the same cell, Choi is detected and the operation fails.
Choi always prefers the safest possible infiltration. So Choi wants to find a path that reaches without being detected, no matter how the robot moves.
Input
The first line contains the integers and , the number of rows and columns of the base, separated by a space. (, )
From the second line through the th line, the information for the boundaries is given. For the boundary between row and row , the first value is the number of laser sensors on that boundary, followed by pairs of a sensor column and a direction , separated by spaces. If is L, the sensor faces left. If is R, the sensor faces right. (, , )
Each laser sensor is placed so that, until it reaches a wall or another laser sensor, it detects every column in its facing direction, including its own column. No input places two different laser sensors at the same position.
Output
Print YES if there is a path that lets Choi reach without being detected by the robot or the laser sensors. Otherwise, print NO.