欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1391D.505
505
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix consisting of rows and columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have their usual meanings — refer to the Notes section for their formal definitions.
Input
The first line of input contains two integers and ( and ) — the number of rows and columns in , respectively.
The following lines each contain characters, each of which is one of 0 and 1. If the -th character on the -th line is 1, then . Similarly, if the -th character on the -th line is 0, then .
Output
Output the minimum number of cells you need to change to make good, or output if it's not possible at all.
Note
In the first case, changing to and to is enough.
You can verify that there is no way to make the matrix in the second case good.
Some definitions —
- A binary matrix is one in which every element is either or .
- A sub-matrix is described by parameters — , , , and ; here, and .
- This sub-matrix contains all elements that satisfy both and .
- A sub-matrix is, further, called an even length square if and is divisible by .
Samples
3 3
101
001
110
2
7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011
-1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |