#P5297. Laser Reflection Cannon Puzzle

    ID: 18530 Type: Default 1000ms 256MiB

Laser Reflection Cannon Puzzle

Laser Reflection Cannon Puzzle

In this problem you are given a game board represented by an n × m grid. Each cell contains one of the following objects:

  • A-type cannon: represented by the character |. It shoots lasers simultaneously in the upward and downward directions.
  • B-type cannon: represented by the character -. It shoots lasers simultaneously in the leftward and rightward directions.
  • Empty cell: represented by .. Lasers pass through an empty cell without changing their direction.
  • Obstacle: represented by #. When a laser hits an obstacle, it vanishes immediately.
  • Reflecting mirror: represented by \. When a laser meets this mirror, it is reflected according to the law of reflection. For a \ mirror the reflection rules are given by: \(\text{up } (-1,0) \to \text{left } (0,-1),\; \text{left } (0,-1) \to \text{up } (-1,0),\; \text{down } (1,0) \to \text{right } (0,1),\; \text{right } (0,1) \to \text{down } (1,0)\).
  • Anti‐reflecting mirror: represented by /. Its reflection rules are: \(\text{up } (-1,0) \to \text{right } (0,1),\; \text{right } (0,1) \to \text{up } (-1,0),\; \text{down } (1,0) \to \text{left } (0,-1),\; \text{left } (0,-1) \to \text{down } (1,0)\).

A cannon emits two laser beams simultaneously in its two designated directions. A laser beam continues in a straight line until it leaves the grid or meets an obstacle. It may be redirected when encountering a mirror as described. Note that laser beams can cross each other without interference. However, if a laser beam goes out of bounds it disappears, and no laser is allowed to hit any cannon (even its own cannon).

The obsessive player, Little N, wants every empty cell to be hit by at least one laser beam, while ensuring that no cannon is hit by any beam. Little N can flip any cannon arbitrarily between A-type and B-type (i.e. change its shooting directions).

Your task is to decide whether there exists an assignment (choice of orientation for each cannon) such that every empty cell is covered by at least one laser beam and no cannon is hit by any beam.

inputFormat

The first line contains two integers n and m, representing the number of rows and columns of the grid.

Then follow n lines, each containing a string of m characters. Each character is one of |, -, ., #, \ or /, representing the object in that cell.

outputFormat

Print YES if there exists an assignment for the cannons such that every empty cell is hit by at least one laser beam while no cannon is hit; otherwise, print NO.

sample

2 3
|..
..-
YES