CF2159B.Rectangles
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a binary grid∗ G of dimensions n×m.
Let us define a rectangle as a tuple (u,d,l,r) that satisfies the following conditions:
- 1≤u<d≤n;
- 1≤l<r≤m;
- Cells (u,l), (u,r), (d,l), (d,r) all contain a 1.
Then, the area of a rectangle (u,d,l,r) is defined as (d−u+1)⋅(r−l+1).
For example, consider the following binary grid given below.
\\begin{matrix} 1 & 0 & 1 & 0 & 1 \\\\ 1 & 0 & 1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 & 1 \\end{matrix}Here, you may see two rectangles (1,2,1,3) and (1,3,3,5)†, each of which has area 6 and 9, respectively.
For each cell (i,j), find the minimum area of any rectangle (u,d,l,r) such that u≤i≤d and l≤j≤r.
∗A binary grid is a grid where each cell contains 0 or 1. The cell on the j-th column of the i-th row is denoted as cell (i,j).
†Note that these are the only rectangles in the grid; for example, (1,1,1,5) is not a rectangle as it does not satisfy u<d.
给你一个 n×m 的二进制网格∗ G。
我们定义一个矩形为一个满足以下条件的四元组 (u,d,l,r):
- 1≤u<d≤n;
- 1≤l<r≤m;
- 单元格 (u,l)、(u,r)、(d,l)、(d,r) 均包含数字 1。
那么,矩形 (u,d,l,r) 的面积定义为 (d−u+1)⋅(r−l+1)。
例如,考虑下面给出的二进制网格:
110000111000101
此处,你可以看到两个矩形 (1,2,1,3) 和 (1,3,3,5)†,其面积分别为 6 和 9。
对每个单元格 (i,j),求满足 u≤i≤d 且 l≤j≤r 的任意矩形 (u,d,l,r) 的最小面积。
∗二进制网格是一个每个单元格只含 0 或 1 的网格。第 i 行第 j 列的单元格记为 (i,j)。
†注意,该网格中仅存在这两个矩形;例如,(1,1,1,5) 不是矩形,因为它不满足 u<d。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and m (2≤n,m, n⋅m≤250000).
Each of the n following lines contains a string of length m denoting the i-th row of G (Gi,j∈0,1).
It is guaranteed that the sum of n⋅m over all test cases does not exceed 250000.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(2≤n,m,且 n⋅m≤250000)。
接下来的 n 行中,每行包含一个长度为 m 的字符串,表示矩阵 G 的第 i 行(其中 Gi,j∈{0,1})。
保证所有测试用例的 n⋅m 之和不超过 250000。
输出格式
For each test case, output a grid of n rows and m columns. On the j-th column of the i-th row, you should output:
- If there exists a rectangle (u,d,l,r) such that u≤i≤d and l≤j≤r, output the minimum area of any such rectangle;
- Otherwise, output 0 instead.
对于每个测试用例,输出一个 n 行 m 列的网格。在第 i 行第 j 列的位置上,应输出:
- 若存在矩形 (u,d,l,r) 满足 u≤i≤d 且 l≤j≤r,则输出所有满足条件的矩形的最小面积;
- 否则,输出 0。
输入输出样例
输入#1
3 3 5 10101 10100 00101 4 6 011101 010001 100010 101110 5 5 11100 10110 11111 01101 00111
输出#1
6 6 6 9 9 6 6 6 9 9 0 0 9 9 9 0 10 8 8 10 10 0 10 8 8 10 10 10 10 8 8 10 0 10 10 8 8 10 0 6 6 6 0 0 6 6 4 4 0 6 4 4 4 6 0 4 4 6 6 0 0 6 6 6
说明/提示
The first test case is explained in the statement.
For the third test case, there are six rectangles that cover at least one cell with minimum area:
- (1,3,1,2), which has area 6;
- (1,2,1,3), which has area 6;
- (3,4,2,3), which has area 4;
- (2,3,3,4), which has area 4;
- (3,5,4,5), which has area 6;
- (4,5,3,5), which has area 6.
第一个测试用例已在题目描述中说明。
对于第三个测试用例,共有六个矩形覆盖至少一个单元格且面积最小:
- (1,3,1,2),其面积为 6;
- (1,2,1,3),其面积为 6;
- (3,4,2,3),其面积为 4;
- (2,3,3,4),其面积为 4;
- (3,5,4,5),其面积为 6;
- (4,5,3,5),其面积为 6。
输入解题思路,AI测评打分。不知道怎么写?