#P3614. YYY Chess

    ID: 16865 Type: Default 1000ms 256MiB

YYY Chess

YYY Chess

This problem is based on a game invented by the ingenious yyy. In order to commemorate the invention, the game is named "YYY Chess". The board is a 7×7 grid where some cells are obstacles labeled with x and the other cells (marked with .) allow moves. Initially, the board is configured as follows:

xx...xx
xx.Y.xx
...Y...
.......
.......
xx...xx
xx...xx

There is only one type of piece, denoted by Y. The initial pieces are system‐given (there are two pieces at positions (2,4) and (3,4) when indexing rows from 1).

A move follows these simple rules:

  • A piece can jump over an adjacent piece (in one of the four directions: up, down, left, right) into the cell immediately beyond.
  • This jump is only allowed if the adjacent cell in that direction contains a piece and the target cell (two cells away) is empty (and not an obstacle).
  • The piece that has been jumped over is removed from the board.

The goal is to remove as many pieces as possible so that at the end only one piece remains. Moreover, due to yyy's perfectionism, the final piece must come to rest at the center of the board (i.e. cell \(\left(4,4\right)\) when using 1-indexed coordinates).

You are given a series of moves. Process the moves sequentially. If an invalid move is encountered, stop processing further moves. After processing, if the board has exactly one piece and that piece is at the center, output YES; otherwise, output NO.

Note: The board rows are numbered from 1 to 7 (top to bottom) and columns from 1 to 7 (left to right). Obstacles (denoted by x) never change.

The jump move in the downward direction is illustrated in the example below:

Before move:
xx...xx
xx.Y.xx
...Y...
.......
.......
xx...xx
xx...xx

After moving the piece at (2,4) downward (jumping over (3,4)): xx...xx xx...xx ....... ...Y... ....... xx...xx xx...xx

</p>

inputFormat

The input begins with an integer m representing the number of moves. Each of the following m lines contains a move in the format:

r c d

Here, r and c are the 1-indexed coordinates of the piece to move, and d is a character indicating the direction: U (up), D (down), L (left), or R (right).

It is guaranteed that m ≥ 0.

outputFormat

Output a single line containing YES if after processing the moves (or stopping at the first invalid move) exactly one piece remains and it is located at the center cell (4,4). Otherwise, output NO.

sample

0
NO