[Solution] XOR with smallest element CodeChef Solution
Problem
Chef has an array of length and an integer .
In one operation, Chef does the following:
- Find the smallest element in the current array. Let this be .
- Next, pick any one index such that
- Finally, replace with
Here denotes the bitwise XOR operation.
For example, if and , then in one move Chef can turn the array into either or .
Chef performs this operation exactly times. Let be final array obtained.
Output the array in sorted order. Note that under this restriction, the output is unique.
👇👇👇👇👇
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains three space-separated integers , , and .
- The second line contains space-separated integers denoting the array .
Output Format
For each test case, output array in sorted order.
Explanation:
Test case : The array is initially . Since there is only one element, it will be modified in each step. So,
- After the first operation, the array is (since )
- After the second operation, the array is (since )
- Continuing the above, it can be verified that after steps, the array is .
Test case : The sequence of steps is as follows:
- Initially, the array is
- After operation , it is
- After operation , it is
- After operation , it is
- After operation , it is
- After operation , it is
- After operation , it is
Remember to print the output in sorted order.
No comments:
Post a Comment