CF425B.Sereja and Table

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Sereja has an n×mn×m rectangular table aa , 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×wh×w , then the component must contain exactly hwhw 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 kk cells of the table so that the table met the described requirement? What minimum number of table cells should he change in this case?

输入格式

The first line contains integers nn , mm and kk (1<=n,m<=100; 1<=k<=10)(1<=n,m<=100; 1<=k<=10) . Next nn lines describe the table aa : the ii -th of them contains mm integers ai1,ai2,...,aima_{i1},a_{i2},...,a_{im} (0<=ai,j<=1)(0<=a_{i,j}<=1) — the values in the cells of the ii -th row.

输出格式

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

输入输出样例

  • 输入#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
    
首页