P29810 [洛谷] [CEOI2021] L-triominoes
提高+
题目描述

Problem Description

Translated from CEOI2021 Day1 T2. L-triominoes.

Problem Description

Given a rectangle of dimensions $H \times W$, we define the smallest $1 \times 1$ rectangle within it as a cell. This rectangle now has $K$ cells missing. The question is whether it is possible to completely cover the entire rectangle using paper pieces shaped as shown below.

Image of L-triomino

A rectangle is considered covered if and only if all non-missing cells are exactly covered once by the paper pieces, with no pieces extending beyond the rectangle or covering the missing cells. The paper pieces can be placed vertically or rotated by $90^\circ$.

Input Format

The first line of input contains three non-negative integers: $W$, $H$, and $K$, representing the number of columns, rows, and the number of missing cells, respectively.

The next $K$ lines each contain two positive integers $x_i$ and $y_i$, representing the coordinates of a missing cell. It is guaranteed that the given cell coordinates are unique.

Output Format

Output a single line containing the string YES if the rectangle can be exactly covered, otherwise output NO.

Sample Input and Output

Sample Input #1

4 3 3
1 1
1 3
4 3

Sample Output #1

YES

Sample Input #2

5 2 4
1 2
2 1
5 1
5 2

Sample Output #2

NO

Sample Input #3

2 3 0

Sample Output #3

YES

Notes/Hints

Sample Explanation

For the first sample, one possible valid coverage is shown below:

Valid coverage for Sample 1

For the second sample, it is impossible to cover the cell at $(1,1)$.

Impossible coverage for Sample 2

For the third sample, one possible valid coverage is shown below:

Valid coverage for Sample 3

Subtasks

All test cases satisfy $1 \leq W \leq 13$, $2 \leq H \leq 10^9$, $0 \leq K \leq 250$, $1 \leq x_i \leq W$, $1 \leq y_i \leq H$.

Subtask Number Score Constraints
1 10 $2 \leq W \leq 13$, $2 \leq H \leq 10^3$, $K \leq 250$
2 7 $2 \leq W \leq 13$, $2 \leq H \leq 10^9$, $K = 0$
3 11 $2 \leq W \leq 3$, $2 \leq H \leq 10^9$, $K \leq 250$
4 17 $4 \leq W \leq 6$, $2 \leq H \leq 10^9$, $K \leq 250$
5 35 $7 \leq W \leq 13$, $2 \leq H \leq 10^9$, $K \leq 250$
6 20 $2 \leq W \leq 13$, $2 \leq H \leq 10^9$, $K \leq 250$
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 3 3 1 1 1 3 4 3
样例输出
YES