CF407D.Largest Submatrix 3

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given matrix a of size n × m, its elements are integers. We will assume that the rows of the matrix are numbered from top to bottom from 1 to n, the columns are numbered from left to right from 1 to m. We will denote the element on the intersecting of the i-th row and the j-th column as a__ij.

We'll call submatrix _i_1, _j_1, _i_2, _j_2 (1 ≤ _i_1 ≤ _i_2 ≤ n; 1 ≤ _j_1 ≤ _j_2 ≤ m) such elements a__ij of the given matrix that _i_1 ≤ i ≤ _i_2 AND _j_1 ≤ j ≤ _j_2. We'll call the area of the submatrix number (_i_2 - _i_1 + 1)·(_j_2 - _j_1 + 1). We'll call a submatrix inhomogeneous, if all its elements are distinct.

Find the largest (in area) inhomogenous submatrix of the given matrix.

给你一个大小为 n×mn \times m 的矩阵 aa,其元素均为整数。我们假设矩阵的行从上到下编号为 11 到 nn,列从左到右编号为 11 到 mm。我们将第 ii 行与第 jj 列交叉位置的元素记作 aija_{ij}。

我们称满足 1≤i1≤i2≤n1 \le i_1 \le i_2 \le n 且 1≤j1≤j2≤m1 \le j_1 \le j_2 \le m 的四元组 (i1,j1,i2,j2)(i_1, j_1, i_2, j_2) 所确定的子矩阵,为原矩阵中所有满足 i1≤i≤i2i_1 \le i \le i_2 且 j1≤j≤j2j_1 \le j \le j_2 的元素 aija_{ij} 构成的子矩阵。该子矩阵的面积定义为 (i2−i1+1)⋅(j2−j1+1)(i_2 - i_1 + 1) \cdot (j_2 - j_1 + 1)。若一个子矩阵中所有元素互不相同,则称其为非均匀子矩阵(inhomogeneous submatrix)。

请找出给定矩阵中面积最大的非均匀子矩阵。

输入格式

The first line contains two integers n, m (1 ≤ n, m ≤ 400) — the number of rows and columns of the matrix, correspondingly.

Each of the next n lines contains m integers a__ij (1 ≤ a__ij ≤ 160000) — the elements of the matrix.

第一行包含两个整数 nn、mm(1 ≤ n, m ≤ 4001 ≤ n, m ≤ 400),分别表示矩阵的行数和列数。

接下来的 nn 行,每行包含 mm 个整数 aija_{ij}(1 ≤ aij ≤ 1600001 ≤ a_{ij} ≤ 160000),表示矩阵的元素。

输出格式

Print a single integer — the area of the optimal inhomogenous submatrix.

输出一个整数——最优非均匀子矩阵的面积。

输入输出样例

  • 输入#1

    3 3
    1 3 1
    4 5 6
    2 6 1

    输出#1

    6
  • 输入#2

    3 4
    5 2 3 1
    3 3 5 3
    4 4 4 5

    输出#2

    4
  • 输入#3

    2 6
    1 2 3 4 5 6
    8 6 7 8 9 1

    输出#3

    8

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

首页