307655: CF1391D. 505
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
505
题意翻译
给出一个 $n \times m$ 的 $01$ 矩阵,如果每个长宽都为偶数的正方形子矩阵内 $1$ 的个数都为奇数,则这是一个“好的”矩阵。如果能把矩阵改成“好的”,问最少改多少个数。如果不能,输出 $-1$。题目描述
A binary matrix is called good if every even length square sub-matrix has an odd number of ones. Given a binary matrix $ a $ consisting of $ n $ rows and $ m $ 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.输入输出格式
输入格式
The first line of input contains two integers $ n $ and $ m $ ( $ 1 \leq n \leq m \leq 10^6 $ and $ n\cdot m \leq 10^6 $ ) — the number of rows and columns in $ a $ , respectively. The following $ n $ lines each contain $ m $ characters, each of which is one of 0 and 1. If the $ j $ -th character on the $ i $ -th line is 1, then $ a_{i,j} = 1 $ . Similarly, if the $ j $ -th character on the $ i $ -th line is 0, then $ a_{i,j} = 0 $ .
输出格式
Output the minimum number of cells you need to change to make $ a $ good, or output $ -1 $ if it's not possible at all.
输入输出样例
输入样例 #1
3 3
101
001
110
输出样例 #1
2
输入样例 #2
7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011
输出样例 #2
-1