CF2194D.Table Cut

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given a table of size n×mn \times m, where each cell contains either 00 or 11. 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 aa be the number of ones in one part of the table after the cut, and bb be the number of ones in the other part of the table. The goal is to maximize the value of a⋅ba \cdot b.

给定一个大小为 n×mn \times m 的表格,其中每个单元格包含 00 或 11。任务是用一条从左上角到右下角的切割线将表格分为两部分,且切割线只能向右或向下延伸。

设切割后表格一部分中 11 的个数为 aa,另一部分中 11 的个数为 bb。目标是最大化 a⋅ba \cdot b 的值。

输入格式

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

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

Each of the following nn lines contains mm integers, where the jj-th number in the ii-th line corresponds to the value ai,ja_{i, j} (0≤ai,j≤10 \leq a_{i, j} \leq 1).

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤3⋅1051 \leq n, m \leq 3 \cdot 10^{5},且 2≤n⋅m≤3⋅1052 \leq n \cdot m \leq 3 \cdot 10^{5}),分别表示表格的行数和列数。

接下来的 nn 行中,每行包含 mm 个整数,其中第 ii 行的第 jj 个数对应值 ai,ja_{i, j}(0≤ai,j≤10 \leq a_{i, j} \leq 1)。

保证所有测试用例的 n⋅mn \cdot m 之和不超过 3⋅1053 \cdot 10^{5}。

输出格式

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 nn characters 'D' and mm characters 'R', representing the direction of the next cut, where 'D' means a cut downwards, and 'R' — a cut to the right.

对于每个测试用例,在输出数据的第一行输出一个数字——乘积的最大值。

在第二行输出一个由 nn 个字符 'D' 和 mm 个字符 'R' 组成的字符串,表示下一次切割的方向,其中 'D' 表示向下切割,'R' 表示向右切割。

输入输出样例

  • 输入#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

    输出#1

    30
    RDRDRDRDDR
    20
    DRRDRDDDR
    4
    DRDRD

说明/提示

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.

图片展示了第一个和第二个测试用例的正确切割方式,此时乘积的值达到最大。

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

首页