デンソークリエイトプログラミングコンテスト2025(AtCoder Beginner Contest 413)
G
Big Banned Grid
AtCoder
⌀ 1723
原题
翻译中…

Problem Statement

翻译中…

There is an $H \times W$ grid. Let $(i,j)$ denote the cell at the $i$-th row $(1\le i\le H)$ from the top and $j$-th column $(1\le j\le W)$ from the left.

翻译中…

Each cell in the grid either has an obstacle placed on it or has nothing placed on it. There are $K$ cells with obstacles: cells $(r_1,c_1),(r_2,c_2),\ldots,(r_K,c_K)$.

翻译中…

Takahashi is initially at cell $(1,1)$ and wants to reach cell $(H,W)$ by repeatedly moving to an adjacent cell (up, down, left, right) that has nothing placed on it.

翻译中…

More precisely, he can repeat the following operation as many times as he likes:

翻译中…
  • Choose one of the following four operations and perform the chosen operation:
  • If $1\lt i$ and cell $(i-1,j)$ has nothing placed on it, move to cell $(i-1,j)$. Otherwise, do not move.
    • If $1\lt j$ and cell $(i,j-1)$ has nothing placed on it, move to cell $(i,j-1)$. Otherwise, do not move.
    • If $i\lt H$ and cell $(i+1,j)$ has nothing placed on it, move to cell $(i+1,j)$. Otherwise, do not move.
    • If $j\lt W$ and cell $(i,j+1)$ has nothing placed on it, move to cell $(i,j+1)$. Otherwise, do not move.
翻译中…

Determine whether he can move from cell $(1,1)$ to cell $(H,W)$.

翻译中…

Constraints

翻译中…
  • $1\le H\le2\times10^5$
  • $1\le W\le2\times10^5$
  • $0\le K\le2\times10^5$
  • $1\le r_i\le H\ (1\le i\le K)$
  • $1\le c_i\le W\ (1\le i\le K)$
  • $(r_i,c_i)\ne(1,1)\ (1\le i\le K)$
  • $(r_i,c_i)\ne(H,W)\ (1\le i\le K)$
  • $(r_i,c_i)\ne(r_j,c_j)\ (1\le i\lt j\le K)$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from standard input in the following format:

翻译中…

H W K
r_1 c_1
r_2 c_2
\vdots
r_K c_K

翻译中…

Output

翻译中…

If Takahashi can move from cell $(1,1)$ to cell $(H,W)$ by repeating the operation described in the problem, print Yes; otherwise, print No.

翻译中…

样例

Input #1
4 5 5
1 4
2 3
3 2
3 4
4 2
Output #1
No
The grid looks as follows: ![image](https://img.atcoder.jp/abc413/b20c1350e9da21a02c8c6a46f0b58a35.png) Takahashi cannot move from cell $(1,1)$ to cell $(4,5)$.
Input #2
2 7 3
1 2
2 4
1 6
Output #2
Yes
The grid looks as follows: ![image](https://img.atcoder.jp/abc413/0e45dcbb4a025ab811e485f6c91ceb36.png) He can move from cell $(1,1)$ to cell $(2,7)$ by moving as shown in the figure.
Input #3
1 1 0
Output #3
Yes
Note that there may be cases where he does not need to move or where no obstacles are placed.
Input #4
10 12 20
8 3
1 11
6 4
3 7
10 4
5 7
4 7
5 5
4 3
6 1
1 6
2 7
6 7
1 3
6 3
2 12
9 6
7 3
3 11
9 7
Output #4
Yes
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。