아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Turn off the Lights

시간 제한5초메모리 제한1024 MB

요약
켜짐과 꺼짐으로 이루어진 격자에서 모든 전구를 끄기 위해 뒤집어야 하는 행 또는 열 구간의 최소 개수를 구한다.
난이도

보통10점 중 7점

유형
비트 연산, 완전 탐색, 그리디, 행렬
정답자
아직 제출이 없습니다

문제

Eunjin has a rectangular-shaped board of light bulbs. It is consisted of RR rows and CC columns, therefore there are RCRC bulbs in total. A light bulb can have either of two states: turned on (often denoted by “1”) or turned off (often denoted by “0”).

Wonha, a mischievous boyfriend, messed up her light board by turning on some bulbs. The other bulbs are currently turned off. After Eunjin noticed his mischief, she decided to turn all the lights off using minimum number of operations. The only operation she can do is to reverse the state of a consecutive sequence of light bulbs in a row or column.

You must write a program that computes the smallest possible number of operations needed for her, to make all the bulbs turned off. It is allowed that some light bulbs to be turned on during the whole process, but after a sequence of appropriate operations, all the bulbs must be turned off.

입력

The input consists of TT test cases. The number of test cases TT is given in the first line of the input.

The first line of each test cases contains two integers RR and CC, which denotes the number of rows and the number of columns, respectively, in the light board. Each of the following RR rows contains a string of CC digits “1” or “0”. Each digit denotes the initial state of each light bulb after Wonha changed the state of some light bulbs: “1” means the bulb is turned on, and “0” means the bulb is turned off. You may assume that both RR and CC are not greater than 1515.

출력

Print exactly one line for each test case. The line should contain an integer indicating the smallest number of operations needed.

예제1

  1. 예제 1

    입력
    1
    5 8
    00100000
    00100000
    11011000
    00100000
    00111100
    
    예상 출력
    3