#P14794. [NERC 2025] Medical Parity
[NERC 2025] Medical Parity
题目描述
Nurse Mira works in an allergy clinic. For each patient Mira tests allergens in a fixed order. The outcome of the tests is written down as a binary string of length : for each allergen, 1 means a positive reaction and 0 means no reaction.
To analyze how the reactions are distributed, Mira also writes a for . For a binary string of length , the parity control string is defined as follows. For every position (), let be the number of characters equal to 1 among the first characters of (including position ). The parity control string is the binary string of length such that for all (). In other words, is 1 if is odd and 0 if is even. For example, if , then .
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 and of the same length . They were intended to be some true test result string and its parity control string , but some bits in and might have been flipped during recording. For instance, in the previous example only the 3rd bit in could have been flipped, resulting in and .
In one , 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 and of length . You want to obtain two strings and of length from and by flipping some bits in and , so that is a parity control string of . Find the minimal possible total number of bit flips needed.
输入格式
The first line of the input contains the number of test cases . The lines follow --- two lines for each test case. The first line of each test case contains a non-empty binary string consisting of characters 0 and 1. The second line contains a binary string consisting of characters 0 and 1 with the same length as .
The total length of all strings in the input does not exceed .
输出格式
Print 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