[Solution] Joint XOR CodeChef Solution | Solution CodeChef
Problem
Chef has a binary string of length . Chef wants to find two substrings of equal length, such that their bitwise XOR is maximised.
Formally, Chef wants to find and such that:
- and
- , that is, the substrings have equal length;
- is maximised, where is the bitwise XOR operation.
Output the maximum XOR value in decimal notation. Since the value can be large, output it module .
Note that a substring is formed by deleting some (possibly zero) characters from the beginning and some (possibly zero) characters from the end of the string.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer denoting the length of string .
- The second line of each test case contains a binary string of length containing s and s only.
Output Format
For each test case, output the maximum XOR value in decimal notation. Since the value can be large, output it module .
Explanation:
Test case : We can choose and . Thus, the chosen substrings are and . The XOR of these substrings is whose decimal equivalent is .
Test case : We can choose and . Thus, the chosen substrings are and . The XOR of these substrings is whose decimal equivalent is .
Test case : We can choose and . Thus, the chosen substrings are and . The XOR of these substrings is whose decimal equivalent is .
No comments:
Post a Comment