#P5791. [CTSC2006] 方块填数

[CTSC2006] 方块填数

Problem Description

Recently, a game of filling numbers in a grid has become popular worldwide.

You are given an n×mn \times m grid. The nn rows are numbered from 11 to nn from top to bottom, and the mm columns are numbered from 11 to mm from left to right. If both the row number and the column number of a cell are odd, then the cell is called an odd cell. At the start of the game, all odd cells are already filled with numbers. You need to fill numbers into the other cells. If after filling, the grid satisfies the following conditions, you win the game:

  1. In every a1×b1a_1 \times b_1 subgrid, the sum of all numbers is greater than 00.
  2. In every a2×b2a_2 \times b_2 subgrid, the sum of all numbers is less than 00.

Here, a1,b1,a2,b2a_1, b_1, a_2, b_2 are all given at the start of the game. An a×ba \times b subgrid refers to the set of all cells whose row indices are from i (1ina+1)i\ (1 \leq i \leq n-a+1) to i+a1i+a-1, and whose column indices are from j (1jmb+1)j\ (1 \leq j \leq m-b+1) to j+b1j+b-1.

Xiao P likes this game very much. He hopes you can help write a program to provide one way to fill the numbers, or tell him that such a way does not exist.

Input Format

The first line contains 66 positive integers separated by spaces: n,m,a1,b1,a2,b2n, m, a_1, b_1, a_2, b_2.

Next, there are n+12\lfloor \frac{n+1}{2} \rfloor lines. Each line contains m+12\lfloor \frac{m+1}{2} \rfloor integers. The j (j=1,2,,m+12)j\ (j=1, 2, \ldots, \lfloor \frac{m+1}{2} \rfloor)-th number on line i+1i+1 represents the integer initially filled in the cell at row 2i12i-1 and column 2j12j-1 of the grid.

Output Format

If no filling scheme exists, output only one line: No.

If a filling scheme exists, first output one line: Yes. Then output nn lines, each containing mm integers separated by spaces, describing a filling scheme. Each output integer must be between 109-10^9 and 10910^9.

3 3 2 2 3 3
1 1
1 1
Yes
1 -1 1
-4 5 -4
1 -1 1

Hint

Sample Explanation

After filling, the sum of the numbers in any 2×22 \times 2 block is 11; the sum of the numbers in any 3×33 \times 3 block is 1-1.

Constraints

For 100%100\% of the testdata, 1n,m,a1,b1,a2,b21001 \leq n, m, a_1, b_1, a_2, b_2 \leq 100. The numbers already filled in the grid are all between 100-100 and 100100.

Translated by ChatGPT 5