CF1102F.Elongated Matrix

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a matrix aa, consisting of nn rows and mm columns. Each cell contains an integer in it.

You can change the order of rows arbitrarily (including leaving the initial order), but you can't change the order of cells in a row. After you pick some order of rows, you traverse the whole matrix the following way: firstly visit all cells of the first column from the top row to the bottom one, then the same for the second column and so on. During the traversal you write down the sequence of the numbers on the cells in the same order you visited them. Let that sequence be s1,s2,…,snms_1, s_2, \dots, s_{nm}.

The traversal is kk-acceptable if for all ii (1≤i≤nm−11 \le i \le nm - 1) ∣si−si+1∣≥k|s_i - s_{i + 1}| \ge k.

Find the maximum integer kk such that there exists some order of rows of matrix aa that it produces a kk-acceptable traversal.

给你一个由 nn 行 mm 列组成的矩阵 aa,其中每个单元格包含一个整数。

你可以任意改变行的顺序(包括保持初始顺序不变),但不能改变每行内部各单元格的顺序。选定某种行顺序后,你按如下方式遍历整个矩阵:首先从上到下访问第一列的所有单元格,然后同样地依次访问第二列、第三列……直到最后一列。在遍历过程中,你按访问顺序将各单元格中的数字依次记录下来,得到序列 s1,s2,…,snms_1, s_2, \dots, s_{nm}。

若对所有 ii(1≤i≤nm−11 \le i \le nm - 1)均满足 ∣si−si+1∣≥k|s_i - s_{i + 1}| \ge k,则称该遍历是 kk-可接受的。

请找出最大的整数 kk,使得存在矩阵 aa 的某种行排列,使其产生的遍历是 kk-可接受的。

输入格式

The first line contains two integers nn and mm (1≤n≤161 \le n \le 16, 1≤m≤1041 \le m \le 10^4, 2≤nm2 \le nm) — the number of rows and the number of columns, respectively.

Each of the next nn lines contains mm integers (1≤ai,j≤1091 \le a_{i, j} \le 10^9) — the description of the matrix.

第一行包含两个整数 nn 和 mm(1≤n≤161 \le n \le 16,1≤m≤1041 \le m \le 10^4,2≤nm2 \le nm),分别表示矩阵的行数和列数。

接下来的 nn 行,每行包含 mm 个整数(1≤ai,j≤1091 \le a_{i, j} \le 10^9),表示该矩阵。

输出格式

Print a single integer kk — the maximum number such that there exists some order of rows of matrix aa that it produces an kk-acceptable traversal.

输出一个整数 kk —— 满足存在矩阵 aa 的某一行排列顺序,使得该排列能产生一个 kk-可接受遍历的最大 kk 值。

输入输出样例

  • 输入#1

    4 2
    9 9
    10 8
    5 3
    4 3

    输出#1

    5
  • 输入#2

    2 4
    1 2 3 4
    10 3 7 3

    输出#2

    0
  • 输入#3

    6 1
    3
    6
    2
    5
    1
    4

    输出#3

    3

说明/提示

In the first example you can rearrange rows as following to get the 55-acceptable traversal:

5 3
10 8
4 3
9 9

Then the sequence ss will be [5,10,4,9,3,8,3,9][5, 10, 4, 9, 3, 8, 3, 9]. Each pair of neighbouring elements have at least k=5k = 5 difference between them.

In the second example the maximum k=0k = 0, any order is 00-acceptable.

In the third example the given order is already 33-acceptable, you can leave it as it is.

在第一个例子中,你可以将行重新排列如下,从而得到一个 55-可接受的遍历:

5 3
10 8
4 3
9 9

此时序列 ss 将为 [5,10,4,9,3,8,3,9][5, 10, 4, 9, 3, 8, 3, 9]。其中每一对相邻元素之间的差值至少为 k=5k = 5。

在第二个例子中,最大的 k=0k = 0,任意顺序都是 00-可接受的。

在第三个例子中,给定的顺序本身已是 33-可接受的,因此你可以保持原样不变。

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

首页