#P15068. [UOI 2024 II Stage] Tic-Tac-Toe

[UOI 2024 II Stage] Tic-Tac-Toe

题目描述

You were playing tic-tac-toe with a friend online. However, there was a problem, another air raid in your area! Being a responsible person, you go to the bomb shelter. After the alarm is over, you come back to finish the game, but something is not right. Your friend may have cheated and changed the board.

You remember the game board AA as it was. Upon returning, you see the same game and the board BB. Can you tell if it is possible to obtain board BB from board AA in no more than one move, made according to the rules?

Please note that the first move is made by the player placing the X\textbf{X}. Also, the standard rule that the game stops if there are three X's or O's in a row does not apply here.

输入格式

The first three lines contain three symbols Ai,jA_{i, j} each, describing the initial board.

The next three lines contain three symbols Bi,jB_{i, j} each, describing the final board.

Each cell of the board is described by three symbols:

  • .\tt{.} --- denotes an empty cell;
  • 0\tt{0} --- denotes a placed O;
  • X\tt{X} --- denotes a placed X.

It is guaranteed that board A can be obtained by a sequence of valid moves from an empty board.

输出格式

Output YES\tt{YES} or NO\tt{NO} (in any case) depending on whether it was possible to obtain board BB from board AA.

.X.
.X.
00.
.X.
.X.
000
NO
.XX
.00
...
XXX
.00
...
YES
XXX
000
...
XXX
000
.X.
YES
0X0
X.X
0X0
X0X
0.0
X0X
NO
.X.
...
...
.X.
...
...
YES

提示

In the first example, one O is added, but it is now the turn to place an X.

In the second example, one X is added.

In the third example, one X is also added. Note that despite having three O's (and X's) in a row, the game does not stop.

In the fourth example, the board is altered.

In the fifth example, no moves were made.