CF1416F.Showing Off

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Another dull quarantine day was going by when BThero decided to start researching matrices of size n×mn \times m. The rows are numerated 11 through nn from top to bottom, and the columns are numerated 11 through mm from left to right. The cell in the ii-th row and jj-th column is denoted as (i,j)(i, j).

For each cell (i,j)(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,j+1)(i, j + 1), (i+1,j)(i + 1, j) or (i−1,j)(i - 1, j), respectively. No transition pointed outside of the matrix.

Let us call a cell (i2,j2)(i_2, j_2) reachable from (i1,j1)(i_1, j_1), if, starting from (i1,j1)(i_1, j_1) and repeatedly moving to the adjacent cell according to our current direction, we will, sooner or later, visit (i2,j2)(i_2, j_2).

BThero decided to create another matrix from the existing two. For a cell (i,j)(i, j), let us denote Si,jS_{i, j} as a set of all reachable cells from it (including (i,j)(i, j) itself). Then, the value at the cell (i,j)(i, j) in the new matrix will be equal to the sum of costs of all cells in Si,jS_{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.

又一个无聊的隔离日过去了,此时 BThero 决定开始研究 n×mn \times m 大小的矩阵。行从上到下编号为 11 至 nn,列从左到右编号为 11 至 mm。第 ii 行第 jj 列的单元格记为 (i,j)(i, j)。

对于每个单元格 (i,j)(i, j),BThero 有两个值:

  1. 单元格的代价(cost),为一个正整数;
  2. 单元格的方向(direction),为字符 L、R、D、U 中的一个,分别对应向相邻单元格 (i,j−1)(i, j - 1)、(i,j+1)(i, j + 1)、(i+1,j)(i + 1, j) 或 (i−1,j)(i - 1, j) 的转移。所有转移均不会指向矩阵外部。

我们称单元格 (i2,j2)(i_2, j_2) 可从 (i1,j1)(i_1, j_1) 到达(reachable),当且仅当我们从 (i1,j1)(i_1, j_1) 出发,反复依据当前单元格的方向移动至相邻单元格,最终(在有限步内)会访问到 (i2,j2)(i_2, j_2)。

BThero 决定基于已有的两个矩阵(即代价矩阵与方向矩阵)构造一个新的矩阵。对单元格 (i,j)(i, j),记 Si,jS_{i, j} 为其所有可达单元格(包括 (i,j)(i, j) 自身)构成的集合。那么新矩阵中单元格 (i,j)(i, j) 处的值即为 Si,jS_{i, j} 中所有单元格的代价之和。

BThero 迅速计算出该新矩阵后,立刻将其发送给了朋友们。然而,他并未保存任何初始矩阵!请帮助他恢复出任意一对合法的初始矩阵(即代价矩阵与方向矩阵),使得它们能生成当前给定的新矩阵。

输入格式

The first line of input file contains a single integer TT (1≤T≤1001 \le T \le 100) denoting the number of test cases. The description of TT test cases follows.

First line of a test case contains two integers nn and mm (1≤n⋅m≤1051 \le n \cdot m \le 10^5).

Each of the following nn lines contain exactly mm integers — the elements of the produced matrix. Each element belongs to the segment [2,109][2, 10^9].

It is guaranteed that ∑(n⋅m)\sum{(n \cdot m)} over all test cases does not exceed 10510^5.

输入文件的第一行包含一个整数 TT(1≤T≤1001 \le T \le 100),表示测试用例的数量。接下来依次描述 TT 个测试用例。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n⋅m≤1051 \le n \cdot m \le 10^5)。

接下来的 nn 行,每行恰好包含 mm 个整数——即所生成矩阵的元素。每个元素均属于区间 [2,109][2, 10^9]。

保证所有测试用例中 n⋅mn \cdot m 的总和不超过 10510^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.

对于每个测试用例,若答案不存在,则输出单个单词 NO;否则,输出 YES,并以与输入相同的格式输出两个矩阵:

  • 第一个矩阵为代价矩阵(cost matrix),第二个矩阵为方向矩阵(direction 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

输入解题思路,AI测评打分。不知道怎么写?

首页