問題一覧 > 通常問題

No.3595 A Queen

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 90
作問者 : 👑 AngrySadEight / テスター : gomaazarasi UT0911 ぽえ
お気に入りにしたユーザー ProblemId : 12703 / 自分の提出
問題文最終更新日: 2026-07-20 21:56:14
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 506 裏・クイーンコンテスト (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。