Again XOR problem
You may have solved a lot of problems related to XOR and we are sure that you liked them, so here is one more problem for you.
You are given a binary string of length . Let string be the result of taking the XOR of all substrings of size of . You need to find the number of 1
bits in .
Note:
- A substring is a continuous part of string which can be obtained by deleting some (may be none) character's from the beginning and some (may be none) character's from the end.
- XOR of many similar-sized strings is defined here.
Input Format
- The first line of the input contains an integer - the number of test cases. The test cases then follow.
- The first line of each test case contains two integers and .
- The second line of each test case contains a binary string of size .
Output Format
For each test case, output on a single line number of 1
bits in the XOR of all substrings of size of .
Constraints
- only contains characters
0
and1
.
Sample Input 1
4
4 1
1010
4 2
1001
4 3
1111
4 4
0110
Sample Output 1
0
2
0
2
Explanation
- Test case : All -sized substrings of are:
0
1
1
0
The XOR of these strings is 0
, therefore the number of 1
bits is .
- Test case : All -sized substrings of are:
10
00
01
The XOR of these strings is 11
, therefore the number of 1
bits is .
- Test case : All -sized substrings of are:
111
111
The XOR of these strings is 000
, therefore the number of 1
bits is .
- Test case : All -sized substrings of are:
0110
The XOR of these strings is 0110
, therefore the number of 1
bits is .
Hii
ReplyDeletecode plz
ReplyDelete