Codeforces Round 1078 (Div. 2)
D
Table Cut
Codeforces
1600
原题
← CE →
翻译中…

Given a table of size $n \times m$, where each cell contains either $0$ or $1$. The task is to divide it into two parts with a cut that goes from the top left corner to the bottom right corner. The cut lines can only go right or down.

翻译中…

Let $a$ be the number of ones in one part of the table after the cut, and $b$ be the number of ones in the other part of the table. The goal is to maximize the value of $a \cdot b$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \leq n, m \leq 3 \cdot 10^{5}$, $2 \leq n \cdot m \leq 3 \cdot 10^{5}$) — the number of rows and columns in the table, respectively.

翻译中…

Each of the following $n$ lines contains $m$ integers, where the $j$-th number in the $i$-th line corresponds to the value $a_{i, j}$ ($0 \leq a_{i, j} \leq 1$).

翻译中…

It is guaranteed that the sum of $n \cdot m$ across all test cases does not exceed $3 \cdot 10^{5}$.

翻译中…

Output

翻译中…

For each test case, output a single number in the first line of the output data — the maximum value of the product.

翻译中…

In the second line, output a string consisting of $n$ characters  'D' and $m$ characters  'R', representing the direction of the next cut, where 'D' means a cut downwards, and 'R' — a cut to the right.

翻译中…

Note

翻译中…

The images show the correct cuts for each of the first and second test cases, at which the maximum value of the product is achieved.

翻译中…

image image

翻译中…

样例

Input #1
3
5 5
1 0 1 1 0
0 1 0 1 1
1 0 1 0 0
0 1 0 1 0
0 0 0 0 1
5 4
0 0 1 0
0 1 1 1
1 0 0 1
0 1 0 1
0 0 1 0
3 2
1 0
0 1
1 1
Output #1
30
RDRDRDRDDR
20
DRRDRDDDR
4
DRDRD
InputCopy OutputCopy
题目信息
题号
2194D
时间限制
2 s
内存限制
256 MB
标签
构造
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。