[Solution] Binary Substituition CodeChef Solution
Problem
Chef has a binary string . He can replace any occurrence of -
- with
- with
- with
- with
While doing these operations, Chef noticed that he can end up with different strings depending upon the order of application of the operations. Given the final string containing only and , Chef wants to know the number of possible strings he might have began with.
As the number of initial strings can be large, print the result modulo .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of a single line of input denoting , the final string obtained after applying the operations.
Output Format
For each test case, output the number of original strings that can result in the final string mod .
Explanation:
Test case : The binary strings that can result in the string are and .
- : Replace the first two characters with and last two characters with . Thus, we get .
- : Replace the characters with .
Test case : The only binary string that can result in the string is . In , we replace the first two characters with and last two characters with as well.
Test case : The binary strings that can result in the string are and .
- : Replace the first two characters with , next two characters with , and last two characters with . Thus, we get .
- : Replace the characters with and the characters with
No comments:
Post a Comment