#607
Unrated
Lights Off
시간 제한
4s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Note: The time limit for this problem is 4s, twice the default.

Bessie wants to go to sleep, but the farm's lights are keeping her awake. How can she turn them off?

Bessie has two bit strings of length NN (2N202\le N\le 20), representing a sequence of lights and a sequence of switches, respectively. Each light is either on (1) or off (0). Each switch is either active (1) or inactive (0).

A move consists of the following sequence of operations:

Toggle exactly one switch (set it to active if it is inactive, or vice versa).For each active switch, toggle the state of the corresponding light (turn it off if it is on, or vice versa).Cyclically rotate the switches to the right by one. Specifically, if the bit string corresponding to the switches is initially s0s1sN1s_0s_1\dots s_{N-1} then it becomes sN1s0s1sN2s_{N-1}s_0s_1\dots s_{N-2}.

For TT (1T21051\le T\le 2\cdot 10^5) instances of the problem above, count the minimum number of moves required to turn all the lights off.

입력

First line contains TT and NN.

Next TT lines each contain a pair of length-NN bit strings.

출력

For each pair, the minimum number of moves required to turn all the lights off.

예제 입력 1

4 3
000 101
101 100
110 000
111 000

예제 출력 1

0
1
3
2

예제 입력 2

1 10
1100010000 1000011000

예제 출력 2

2

점수

Inputs 3-5: N8N \le 8Inputs 6-13: N18N\le 18Inputs 14-20: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.