#P10635. BZOJ3517 翻硬币

BZOJ3517 翻硬币

Problem Description

There is an n×nn \times n chessboard, and each cell has a coin on it. nn is even. Each coin is either heads up or tails up. In one operation, you may choose a cell (x,y)(x,y), and then flip all coins in row xx and all coins in column yy. Find the minimum number of operations needed to make all coins show the same side.

Input Format

The first line contains a positive integer nn. The next nn lines each contain a 0101 string of length nn, representing the states of the coins on the board.

Output Format

Only one line, the minimum number of operations needed.

4
0101
1000
0010
0101
2

Hint

Sample Explanation.

Perform operations on (2,3)(2,3) and (3,1)(3,1), and finally all coins become 11.

Constraints.

For all data, 1n10001\leq n \leq 1000.

Translated by ChatGPT 5