CF425B.Sereja and Table

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Sereja has an n × m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a component form a rectangle of size h × w, then the component must contain exactly hw cells.

A connected component of the same values is a set of cells of the table that meet the following conditions:

  • every two cells of the set have the same value;
  • the cells of the set form a connected region on the table (two cells are connected if they are adjacent in some row or some column of the table);
  • it is impossible to add any cell to the set unless we violate the two previous conditions.

Can Sereja change the values of at most k cells of the table so that the table met the described requirement? What minimum number of table cells should he change in this case?

Sereja 有一个 n×mn \times m 的矩形表格 aa,其中每个单元格包含数字 0 或 1。Sereja 希望他的表格满足如下要求:所有相同数值的连通块均构成一个边与表格边平行的矩形。这些矩形必须是“实心”的,即:若某个连通块构成一个大小为 h×wh \times w 的矩形,则该连通块必须恰好包含 hwhw 个单元格。

相同数值的一个连通块是指表格中满足以下条件的一组单元格:

  • 该集合中任意两个单元格具有相同的数值;
  • 该集合中的单元格在表格上构成一个连通区域(两个单元格相邻当且仅当它们位于表格的同一行或同一列且彼此紧邻);
  • 无法向该集合中添加任何其他单元格而不违反上述两个条件。

Sereja 最多可以修改表格中 kk 个单元格的值,使得表格满足上述要求吗?在此前提下,他至少需要修改多少个单元格?

输入格式

The first line contains integers n, m and k (1 ≤ n, m ≤ 100; 1 ≤ k ≤ 10). Next n lines describe the table a: the i-th of them contains m integers _a__i_1, _a__i_2, ..., a__im (0 ≤ a__i, j ≤ 1) — the values in the cells of the i-th row.

第一行包含整数 nn、mm 和 kk(1 ≤ n, m ≤ 1001 \le n, m \le 100;1 ≤ k ≤ 101 \le k \le 10)。接下来的 nn 行描述表格 aa:其中第 ii 行包含 mm 个整数 ai1, ai2, ..., aima_{i1}, a_{i2}, ..., a_{im}(0 ≤ ai,j ≤ 10 \le a_{i,j} \le 1),表示第 ii 行各单元格中的值。

输出格式

Print -1, if it is impossible to meet the requirement. Otherwise, print the minimum number of cells which should be changed.

如果无法满足要求,则输出 -1;否则,输出需要更改的最少格子数。

输入输出样例

  • 输入#1

    5 5 2
    1 1 1 1 1
    1 1 1 1 1
    1 1 0 1 1
    1 1 1 1 1
    1 1 1 1 1

    输出#1

    1
  • 输入#2

    3 4 1
    1 0 0 0
    0 1 1 1
    1 1 1 0

    输出#2

    -1
  • 输入#3

    3 4 1
    1 0 0 1
    0 1 1 0
    1 0 0 1

    输出#3

    0

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

首页