[Solution] Alternative Sufferings CodeChef Solution
Problem
You are given a binary string .
In one second, the following scenario happens simultaneously and independently for all the bits which are set to in the string:
- Change the bit from to .
- If the left neighbour exists and is , change it to .
- If the right neighbour exists and is , change it to .
For example, if initially, then after second, (the bit and both its neighbours were changed). After another second, . Here, the first and the last bit were changed to because earlier they were . The middle bit was changed because it was earlier and it was a neighbour of a bit.
Find out the string after seconds.
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 two space-separated integers and — the length of string and the number of seconds.
- The next line describes the string .
Output Format
For each test case, output the string after exactly seconds.
Explanation:
Test case : The middle bit is changed to since it had a neighbouring set bit (in this case both left and right) and both the set bits are changed to . Hence, after one second, it is .
Test case : After first second, the string will be . After another second , the string becomes .
No comments:
Post a Comment