Codeforces Round 243 (Div. 1)
B
Sereja and Table
Codeforces
2200
原题
← AC →
翻译中…

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?

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #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
Output #1
1
InputCopy OutputCopy
Input #2
3 4 1
1 0 0 0
0 1 1 1
1 1 1 0
Output #2
-1
InputCopy OutputCopy
Input #3
3 4 1
1 0 0 1
0 1 1 0
1 0 0 1
Output #3
0
InputCopy OutputCopy
题目信息
题号
425B
时间限制
1 s
内存限制
256 MB
标签
位运算
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。