#P2622. 关灯问题 II

关灯问题 II

Description

There are nn lamps and mm buttons. Each button can control all nn lamps simultaneously — pressing the ii-th button affects every lamp. For lamp jj, pressing button ii has one of the following three effects:

  • If ai,j=1a_{i,j} = 1, then if this lamp is on, turn it off; otherwise do nothing.
  • If ai,j=1a_{i,j} = -1, then if this lamp is off, turn it on; otherwise do nothing.
  • If ai,j=0a_{i,j} = 0, do nothing regardless of the lamp’s state.

All lamps are initially on. Given the effects of every button on every lamp, find the minimum number of button presses needed to turn all lamps off.

Input Format

The first line contains the integer nn.
The second line contains the integer mm.

The next mm lines each contain nn integers. On line i+2i + 2, the jj-th integer is ai,ja_{i,j}, representing the effect of button ii on lamp jj.

Output Format

Output a single integer — the minimum number of button presses. If it is impossible to turn all lamps off, output 1-1.

3
2
1 0 1
-1 1 0
2

Hint

Constraints

  • For 20%20\% of the testdata, printing “no solution” can score points.
  • For 20%20\% of the testdata, n5n \le 5.
  • For 20%20\% of the testdata, m20m \le 20.

The above test points may overlap.

For 100%100\% of the testdata, 1n101 \le n \le 10, 1m1001 \le m \le 100.

Translated by ChatGPT 5