9115: Puzzle: Arithmetic Square

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

题目描述

Grammy is a puzzle master. Today, she is playing a variant of "Arithmetic Square" puzzle.

The puzzle consists of a (2n−1)×(2m−1)(2n-1) \times (2m-1)(2n1)×(2m1) grid. The intersection of odd rows and odd columns are empty and needed to be filled in with pairwise distinct integers. The intersection of even rows and even columns are blocked. All other cells consists of either "+\texttt{+}+" or "-\texttt{-}-".

Each odd row and odd column forms an expression in the grid. The expressions should evaluate to the clues given in the right of the grid and in the bottom of the grid. The goal is to fill in all the empty squares with pairwise distinct integers so that all of the expressions are satisfied.



The left picture illustrates a 5×55\times 55×5 empty puzzle, and the right picture shows a solution to the puzzle.

Grammy surely knows how to solve the puzzle, but she decided to give you a quiz. Please solve the puzzle.

输入格式

The first line contains two integers n,mn,mn,m (2≤n,m≤10002 \leq n,m \leq 10002n,m1000), denoting the size of the grid. 

The following 2n−12n-12n1 lines contains 2m−12m-12m1 characters each, denoting the symbols in the grid. ".\texttt{.}." denotes an empty cell, "\texttt{#}" denotes a blocked cell, "+\texttt{+}+" denotes a plus sign, and "-\texttt{-}-" denotes a minus sign. 
The next line contains nnn integers rir_iri (−109≤ri≤109-10^9 \leq r_i \leq 10^9109ri109), denoting the clues for each row on the right of the grid. 
The next line contains mmm integers cic_ici (−109≤ci≤109-10^9 \leq c_i \leq 10^9109ci109), denoting the clues for each column on the bottom of the grid.

输出格式

If the solution does not exist, output "NO\texttt{NO}NO" on a single line.
Otherwise, output "YES\texttt{YES}YES" on the first line, then output nnn lines, each of which contains mmm integers aija_{ij}aij (−1015≤aij≤1015-10^{15} \leq a_{ij} \leq 10^{15}1015aij1015), denoting the numbers filled into the grid.
If there are multiple solutions, output any.

输入样例 复制

3 3
.-.+.
+#+#-
.-.+.
+#+#+
.-.-.
5 1 -5
14 16 -1

输出样例 复制

YES
7 3 1
2 9 8
5 4 6

分类标签