Escape Sequences
Time limit1sMemory limit512 MB
For a morphism f that replaces a with aa and b with ab, find the smallest k such that t is a substring of the k-fold iterate f^k(s).
- Level
Hard8 of 10
- Topics
- String, Divide and conquer, Math, Binary search
- Solved
- No attempts yet
Problem
For a string consisting of only 'a' and 'b', let be the string obtained by replacing every 'a' in with 'aa' and every 'b' with 'ab'. For example, "aba""aaabaa"$.
Given strings and , find the smallest non-negative integer such that is a contiguous substring of .
is defined as follows.
Input
The first line and the second line contain string and string respectively ().
Strings and consist of only the characters 'a' and 'b'.
Output
Print a single integer, the minimum .
If does not exist, print "-1" instead.