A9377 | Sereja and Table
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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?
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?
输入格式
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_{i1},a_{i2},...,a_{im}$ $(0<=a_{i,j}<=1)$ — the values in the cells of the $i$ -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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted