#P14794. [NERC 2025] Medical Parity

[NERC 2025] Medical Parity

题目描述

Nurse Mira works in an allergy clinic. For each patient Mira tests nn allergens in a fixed order. The outcome of the tests is written down as a binary string xx of length nn: for each allergen, 1 means a positive reaction and 0 means no reaction.

To analyze how the reactions are distributed, Mira also writes a parity control string\emph{parity control string} for xx. For a binary string xx of length nn, the parity control string yy is defined as follows. For every position ii (1in1 \le i \le n), let cic_i be the number of characters equal to 1 among the first ii characters of xx (including position ii). The parity control string yy is the binary string of length nn such that yi=cimod2y_i = c_i \mod 2 for all ii (1in1 \le i \le n). In other words, yiy_i is 1 if cic_i is odd and 0 if cic_i is even. For example, if x=11101x = 11101, then y=10110y = 10110.

Unfortunately, when recording the data, some bits in the test result string and the parity control string may have been written incorrectly. For a given patient, Mira later finds in the system two binary strings xx' and yy' of the same length nn. They were intended to be some true test result string xx and its parity control string yy, but some bits in xx and yy might have been flipped during recording. For instance, in the previous example only the 3rd bit in yy could have been flipped, resulting in x=11101x' = 11101 and y=10010y' = 10010.

In one bit flip\emph{bit flip}, a position in one of the two strings is chosen and the bit at this position is flipped (changing 0 to 1 or 1 to 0). Mira wants to know the minimal number of bit flips that could have happened when recording the data.

Formally, you are given two binary strings xx' and yy' of length nn. You want to obtain two strings xx and yy of length nn from xx' and yy' by flipping some bits in xx' and yy', so that yy is a parity control string of xx. Find the minimal possible total number of bit flips needed.

输入格式

The first line of the input contains the number of test cases tt. The 2t2t lines follow --- two lines for each test case. The first line of each test case contains a non-empty binary string xx' consisting of characters 0 and 1. The second line contains a binary string yy' consisting of characters 0 and 1 with the same length as xx'.

The total length of all xx' strings in the input does not exceed 10610^6.

输出格式

Print tt lines --- one line for each test case. For each test case, print a single integer --- the minimal possible number of bit flips that could have happened when recording the data.

3
11101
10110
11101
10010
01100
10110
0
1
2