L-system Substring
Time limit1sMemory limit128 MB
Given a D0L system over {a,b} and a query z, decide whether z appears as a contiguous substring of some word derivable from the start word.
- Level
Hard8 of 10
- Topics
- String, Simulation, Implementation, Brute force
- Solved
- No attempts yet
Problem
A D0L system (a deterministic Lindenmayer system without interaction) consists of a finite alphabet , a finite set of productions , and a starting string . Every production has the form , where and (a nonempty string over ); for each symbol the set contains exactly one production whose left side is .
A direct derivation turns one string into another by simultaneously replacing every symbol of the string with the right side of its production. The language of the system is the set of all strings that can be obtained from by applying zero or more direct derivations (so itself belongs to the language).
Here the alphabet is , so there are exactly two productions, and with , and the starting string is .
Given a string , decide whether the language contains at least one string of the form with — equivalently, whether occurs as a contiguous substring of some string in the language.
Input
The input contains several blocks and ends at end of file; there are no blank lines between consecutive blocks. Each block consists of exactly four lines:
- the right side of the production ;
- the right side of the production ;
- the starting string ;
- the query string .
Each of these four strings is nonempty, consists only of the letters and , and has length at most .
Output
For each block, print a single line containing YES if some string in the language contains as a substring, and NO otherwise.