A13863 | Showing Off
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Another dull quarantine day was going by when BThero decided to start researching matrices of size $n \times m$ . The rows are numerated $1$ through $n$ from top to bottom, and the columns are numerated $1$ through $m$ from left to right. The cell in the $i$ -th row and $j$ -th column is denoted as $(i, j)$ .
For each cell $(i, j)$ BThero had two values:
1. The cost of the cell, which is a single positive integer.
2. The direction of the cell, which is one of characters L, R, D, U. Those characters correspond to transitions to adjacent cells $(i, j - 1)$ , $(i, j + 1)$ , $(i + 1, j)$ or $(i - 1, j)$ , respectively. No transition pointed outside of the matrix.
Let us call a cell $(i_2, j_2)$ reachable from $(i_1, j_1)$ , if, starting from $(i_1, j_1)$ and repeatedly moving to the adjacent cell according to our current direction, we will, sooner or later, visit $(i_2, j_2)$ .
BThero decided to create another matrix from the existing two. For a cell $(i, j)$ , let us denote $S_{i, j}$ as a set of all reachable cells from it (including $(i, j)$ itself). Then, the value at the cell $(i, j)$ in the new matrix will be equal to the sum of costs of all cells in $S_{i, j}$ .
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.
For each cell $(i, j)$ BThero had two values:
1. The cost of the cell, which is a single positive integer.
2. The direction of the cell, which is one of characters L, R, D, U. Those characters correspond to transitions to adjacent cells $(i, j - 1)$ , $(i, j + 1)$ , $(i + 1, j)$ or $(i - 1, j)$ , respectively. No transition pointed outside of the matrix.
Let us call a cell $(i_2, j_2)$ reachable from $(i_1, j_1)$ , if, starting from $(i_1, j_1)$ and repeatedly moving to the adjacent cell according to our current direction, we will, sooner or later, visit $(i_2, j_2)$ .
BThero decided to create another matrix from the existing two. For a cell $(i, j)$ , let us denote $S_{i, j}$ as a set of all reachable cells from it (including $(i, j)$ itself). Then, the value at the cell $(i, j)$ in the new matrix will be equal to the sum of costs of all cells in $S_{i, j}$ .
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 $T$ ( $1 \le T \le 100$ ) denoting the number of test cases. The description of $T$ test cases follows.
First line of a test case contains two integers $n$ and $m$ ( $1 \le n \cdot m \le 10^5$ ).
Each of the following $n$ lines contain exactly $m$ integers — the elements of the produced matrix. Each element belongs to the segment $[2, 10^9]$ .
It is guaranteed that $\sum{(n \cdot m)}$ over all test cases does not exceed $10^5$ .
First line of a test case contains two integers $n$ and $m$ ( $1 \le n \cdot m \le 10^5$ ).
Each of the following $n$ lines contain exactly $m$ integers — the elements of the produced matrix. Each element belongs to the segment $[2, 10^9]$ .
It is guaranteed that $\sum{(n \cdot m)}$ over all test cases does not exceed $10^5$ .
输出格式
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.
- 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
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted