#P5791. Filling the Block Numbers Game
Filling the Block Numbers Game
Filling the Block Numbers Game
You are given an n × m board. The rows are numbered from 1 to n (top to bottom) and the columns from 1 to m (left to right). A cell (i, j) is called an odd cell if both i and j are odd. At the beginning of the game, every odd cell is already filled with an integer. Your task is to fill in the remaining cells with integers, so that after filling the board the following conditions are satisfied:
- For every subrectangle of size \(a_1 \times b_1\), the sum of all the numbers in that subrectangle is greater than 0.
- For every subrectangle of size \(a_2 \times b_2\), the sum of all the numbers in that subrectangle is less than 0.
A subrectangle of size \(a \times b\) is defined as the set of cells from row i to row i + a - 1 and from column j to column j + b - 1, where \(1 \leq i \leq n - a + 1\) and \(1 \leq j \leq m - b + 1\).
If a valid complete filling exists, output the filled board. Otherwise, output NO (without quotes).
inputFormat
The first line contains six integers \(n\), \(m\), \(a_1\), \(b_1\), \(a_2\), and \(b_2\).
The next \(n\) lines each contain \(m\) tokens. For every odd cell (i.e. cells where both the row index and the column index are odd), an integer is given which is the pre-filled number. For every other cell, the token will be a question mark '?' indicating that the cell is initially empty and needs to be filled.
It is guaranteed that the number of test cases (hidden) will be more than two.
outputFormat
If a valid filling exists, output the completed board in the same format as the input grid (\(n\) lines with \(m\) numbers separated by spaces). Otherwise, output a single line containing NO (without quotes).
sample
1 1 1 1 1 1
5
NO