No.3595 A Queen
タグ : / 解いたユーザー数 90
作問者 : 👑
UT0911
ぽえ
Problem Statement
There is a grid with $N$ rows and $N$ columns. The square at the $i(1 \leq i \leq N)$-th row from the top and the $j(1 \leq j \leq N)$-th column from the left is denoted by square $(i, j)$.
There is $1$ queen piece on square $(1, 1)$. This queen piece can freely enter and leave squares within the grid, but cannot enter or leave squares outside the grid.
You are given a square $(h, w)$ other than square $(1, 1)$. Determine whether the queen piece can reach square $(h, w)$ by moving it exactly $1$ time.
How the queen piece moves (click to expand)
In $1$ move, the queen piece can advance any number of squares in a vertical, horizontal, or diagonal direction, as long as all squares on its path can be entered and left. However, staying on the current square does not count as $1$ move. Strictly speaking, a queen piece on square $(i, j)$ can make the following moves.
- For a positive integer $k$, it can move to square $(i, j + k)$ if and only if the following condition is satisfied.
- For all integers $l$ satisfying $1 \leq l \leq k$, square $(i, j + l)$ is a square that the queen piece can enter and leave.
- For a positive integer $k$, it can move to square $(i, j - k)$ if and only if the following condition is satisfied.
- For all integers $l$ satisfying $1 \leq l \leq k$, square $(i, j - l)$ is a square that the queen piece can enter and leave.
- For a positive integer $k$, it can move to square $(i + k, j)$ if and only if the following condition is satisfied.
- For all integers $l$ satisfying $1 \leq l \leq k$, square $(i + l, j)$ is a square that the queen piece can enter and leave.
- For a positive integer $k$, it can move to square $(i - k, j)$ if and only if the following condition is satisfied.
- For all integers $l$ satisfying $1 \leq l \leq k$, square $(i - l, j)$ is a square that the queen piece can enter and leave.
- For a positive integer $k$, it can move to square $(i + k, j + k)$ if and only if the following condition is satisfied.
- For all integers $l$ satisfying $1 \leq l \leq k$, square $(i + l, j + l)$ is a square that the queen piece can enter and leave.
- For a positive integer $k$, it can move to square $(i + k, j - k)$ if and only if the following condition is satisfied.
- For all integers $l$ satisfying $1 \leq l \leq k$, square $(i + l, j - l)$ is a square that the queen piece can enter and leave.
- For a positive integer $k$, it can move to square $(i - k, j + k)$ if and only if the following condition is satisfied.
- For all integers $l$ satisfying $1 \leq l \leq k$, square $(i - l, j + l)$ is a square that the queen piece can enter and leave.
- For a positive integer $k$, it can move to square $(i - k, j - k)$ if and only if the following condition is satisfied.
- For all integers $l$ satisfying $1 \leq l \leq k$, square $(i - l, j - l)$ is a square that the queen piece can enter and leave.
Constraints
- All inputs are integers.
- $2 \leq N \leq 8$
- $1 \leq h, w \leq N$
- $(h, w) \neq (1, 1)$
Input
The input is given from standard input in the following format.
$N$ $h$ $w$
Output
If the queen piece can reach square $(h, w)$, print Yes; otherwise, print No.
Sample
Sample 1
Input
5 1 4
Output
Yes
The queen piece can reach square $(1, 4)$ in exactly $1$ move. Therefore, print Yes.
Sample 2
Input
8 3 5
Output
No
The queen piece cannot reach square $(3, 5)$ in exactly $1$ move. Therefore, print No.
Sample 3
Input
8 8 8
Output
Yes
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。