No.870 Invincible Castle
Problem Statement
A shogi tournament is going to be held as a school event.
In order to take first place in the tournament, Hifumi looked up a formation called the Invincible Castle on the Internet.
The Invincible Castle is a formation obtained by moving 3 of the pieces placed on a $9\times9$ shogi board according to the following rules.
Definition of the Invincible Castle:
Let A, B, and C be the pieces initially placed at coordinates $(2,8), (3,9), (7,9)$, respectively.
Move piece A to coordinates $(5,8)$, move piece B to coordinates $(4,8)$, and move piece C to coordinates $(6,8)$.
This placement of the 3 pieces is the Invincible Castle.
Hifumi, who took part in the shogi tournament, moved the piece at coordinates $(x_{i1}, y_{i1})$ to $(x_{i2}, y_{i2})$ on move $i$.
Write a program that determines whether the placement of the pieces after $N$ moves is the Invincible Castle.
In other words, determine whether, based on the movement on each move $i$, the pieces initially placed at coordinates (2,8),(3,9),(7,9) respectively end up at coordinates (5,8),(4,8),(6,8).
It is guaranteed in the test cases that no two pieces overlap on one coordinate. That is, a piece is never moved onto coordinates where another piece is already placed.
Also, the test cases do not follow the official rules of shogi.
Input
$N$
$x_{11}$ $y_{11}$ $x_{12}$ $y_{12}$
$x_{21}$ $y_{21}$ $x_{22}$ $y_{22}$
...
$x_{N1}$ $y_{N1}$ $x_{N2}$ $y_{N2}$
・$3 \le N \le 20$
・$1 \le x_{i1}, x_{i2}, y_{i1}, y_{i2} < 10$
・There is no move to the same location
・All input values are integers
Output
Print YES if the placement of the pieces after $N$ moves is the Invincible Castle, and NO otherwise.
Sample
Sample 1
Input
3 7 9 6 8 2 8 5 8 3 9 4 8
Output
YES
The order in which the pieces are moved does not matter; it is enough that the placement of the pieces after $N$ moves is the Invincible Castle.
Sample 2
Input
7 3 9 3 8 4 9 4 8 3 8 4 9 4 9 5 8 4 8 4 9 2 8 4 8 7 9 6 8
Output
NO
The Invincible Castle is not a formation in which piece B, initially placed at coordinates $(3,9)$, is moved to coordinates $(5,8)$, but one in which piece A, initially placed at coordinates $(2,8)$, is moved to coordinates $(5,8)$.
Sample 3
Input
8 7 7 7 6 5 9 5 8 5 8 5 9 2 8 1 8 7 9 6 8 1 8 5 8 1 9 1 8 3 9 4 8
Output
YES
When $3 < N$, various ways of moving the pieces are possible to reach the final goal, the piece placement of the Invincible Castle.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tkr987