#x1051. CF1416F Showing Off
CF1416F Showing Off
Showing Off
题面翻译
对于大小为 的矩阵 和 ,其中 的每个元素为一个权值 , 的每个元素为一个方向 L/R/D/U
初始你在 ,若 ,你可以走到 处,依次类推。
定义 表示从 出发能够到达的点的 的和。
给定矩阵 ,构造 和 使得其生成的矩阵为
的每个元素均为正整数。
题目描述
Another dull quarantine day was going by when BThero decided to start researching matrices of size . The rows are numerated through from top to bottom, and the columns are numerated through from left to right. The cell in the -th row and -th column is denoted as .
For each cell BThero had two values:
- The cost of the cell, which is a single positive integer.
- The direction of the cell, which is one of characters L, R, D, U. Those characters correspond to transitions to adjacent cells , , or , respectively. No transition pointed outside of the matrix.
Let us call a cell reachable from , if, starting from and repeatedly moving to the adjacent cell according to our current direction, we will, sooner or later, visit .
BThero decided to create another matrix from the existing two. For a cell , let us denote as a set of all reachable cells from it (including itself). Then, the value at the cell in the new matrix will be equal to the sum of costs of all cells in .
After quickly computing the new matrix, BThero immediately sent it to his friends. However, he did not save any of the initial matrices! Help him to restore any two valid matrices, which produce the current one.
输入格式
The first line of input file contains a single integer ( ) denoting the number of test cases. The description of test cases follows.
First line of a test case contains two integers and ( ).
Each of the following lines contain exactly integers — the elements of the produced matrix. Each element belongs to the segment .
It is guaranteed that over all test cases does not exceed .
输出格式
For each test case, if an answer does not exist, print a single word NO. Otherwise, print YES and both matrices in the same format as in the input.
- The first matrix should be the cost matrix and the second matrix should be the direction matrix.
- All integers in the cost matrix should be positive.
- All characters in the direction matrix should be valid. No direction should point outside of the matrix.
样例 #1
样例输入 #1
2
3 4
7 6 7 8
5 5 4 4
5 7 4 4
1 1
5
样例输出 #1
YES
1 1 1 1
2 1 1 1
3 2 1 1
R D L L
D R D L
U L R U
NO