P23078 [AtCoder] Grid Game
提高+
题目描述

Problem Description

(Updated at 12:44) For onsite participants, the submissions made before 12:34 have been rejudged. For open participants, the rejudging is still ongoing, so please wait.
(Updated at 14:47) The rejudging of open participants' submissions has also been completed.
The test cases for submissions made after 12:34 are correct. There is a 2D grid board with a vertical length of $ R $ and a horizontal length of $ C $. The coordinates of the top-left cell are $ (1,1) $, and the coordinates of the bottom-right cell are $ (R,C) $.

This board will undergo the following operation $ N $ times:

  • Paint all cells within a rectangular section black. Specifically, given $ r, c, h, w $, start painting from the top-left coordinates $ (r, c) $, and paint all $h \times w$ cells within the rectangular section black.

You love black cells and want to move from one point on the board to another, only stepping on black cells. You can move to any of the four adjacent cells. You cannot move outside the board.

Given the coordinates of the start cell $ (r_s, c_s) $, the goal cell $ (r_g, c_g) $, and several operations, output YES if you can reach the goal cell only by moving on black cells, and NO if you cannot reach the goal or if the start or goal cells are not black.

Input Format

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

$ R $ $ C $ $ r_s $ $ c_s $ $ r_g $ $ c_g $ $ N $ $ r_1 $ $ c_1 $ $ h_1 $ $ w_1 $ $ r_2 $ $ c_2 $ $ h_2 $ $ w_2 $ : $ r_N $ $ c_N $ $ h_N $ $ w_N $

  • The first line contains the integers $R, C\ (1 \leq R, C \leq 48)$, representing the vertical and horizontal lengths of the board.
  • The second line contains the integers $r_s\ (1 \leq r_s \leq R)$ and $c_s\ (1 \leq c_s \leq C)$, representing the coordinates of the start cell.
  • The third line contains the integers $r_g\ (1 \leq r_g \leq R)$ and $c_g\ (1 \leq c_g \leq C)$, representing the coordinates of the goal cell.
  • The fourth line contains the integer $N\ (1 \leq N \leq 1000)$, representing the number of operations.
  • The next $ N $ lines contain the information of the rectangles. The $ i $-th line contains the integers $r_i\ (1 \leq r_i \leq R), c_i\ (1 \leq c_i \leq C), h_i\ (1 \leq r_i + h_i - 1 \leq R), w_i\ (1 \leq c_i + w_i - 1 \leq C)$, representing the coordinates and dimensions of the $ i $-th rectangle.
  • The start and goal cells are always different, i.e., $(r_s, c_s) \neq (r_g, c_g)$.

Output Format

Output YES or NO according to the problem statement in one line. Do not forget the newline at the end.

Sample Input and Output

Sample Input #1

4 5
2 2
3 5
2
2 2 1 4
3 5 2 1

Sample Output #1

YES

Sample Input #2

4 5
1 2
2 2
2
1 1 1 5
1 1 4 1

Sample Output #2

NO

Sample Input #3

4 5
1 1
1 3
3
1 1 1 1
1 2 1 1
1 3 1 1

Sample Output #3

YES

Sample Input #4

1 5
1 1
1 2
1
1 3 1 2

Sample Output #4

NO

Sample Input #5

1 5
1 3
1 2
1
1 3 1 2

Sample Output #5

NO

Sample Input #6

48 48
1 1
48 48
1
1 1 48 48

Sample Output #6

YES

Notes/Hints

Sample Explanation 1

If white cells are represented by . and black cells by #, the board after the painting operations looks like this:

.....
.####
....#
....#

With the start cell S and the goal cell G, the positions are as follows:

.....
.S...
....G
.....
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

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