CF375B.Maximum Submatrix 2

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?

Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.

给你一个由数字 0 和 1 构成的矩阵,其大小为 $ n \times m $。你可以任意重排该矩阵的行。在执行上述操作后,所能得到的全由 1 组成的子矩阵的最大面积是多少?

假设矩阵 $ a $ 的行从上到下编号为 $ 1 $ 到 $ n $,列从左到右编号为 $ 1 $ 到 $ m $。位于第 $ i $ 行、第 $ j $ 列的矩阵单元格可表示为 $ (i,,j) $。形式化地,矩阵 $ a $ 的一个子矩阵由四个整数 $ d,,u,,l,,r $(满足 $ 1 \le d \le u \le n ;; 1 \le l \le r \le m $)确定。我们规定该子矩阵包含所有满足 $ d \le i \le u $ 且 $ l \le j \le r $ 的单元格 $ (i,,j) $。该子矩阵的面积即为其所含单元格的总数。

输入格式

The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.

第一行包含两个整数 nn 和 mm(1≤n,m≤50001 \leq n, m \leq 5000)。接下来的 nn 行,每行包含 mm 个字符,构成矩阵 aa。矩阵 aa 仅包含字符 "0" 和 "1"。注意:每行中的矩阵元素之间不包含任何空格。

输出格式

Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.

输出一个整数——所得最大子矩阵的面积。如果我们无法得到一个全为数字 1 的矩阵,则输出 0。

输入输出样例

  • 输入#1

    1 1
    1

    输出#1

    1
  • 输入#2

    2 2
    10
    11

    输出#2

    2
  • 输入#3

    4 3
    100
    011
    000
    101

    输出#3

    2

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

首页