#B3950. Syllable Pattern Matching in szm Language
Syllable Pattern Matching in szm Language
Syllable Pattern Matching in szm Language
In modern szm language, words are written in Roman letters and are segmented into syllables according to the following rules:
- The vowels are
a
,e
,i
,o
, andu
. - Generally, a syllable contains exactly one vowel and ends with that vowel.
- Special case: If a character
n
is encountered and the next character (if any) is not a vowel, thenn
forms a syllable on its own. - Each syllable has at most 3 characters.
For example, the string shinzanmono
is segmented into syllables as follows:
shi, n, za, n, mo, no
Similarly, naku
is segmented as:
na, ku
Assume that any string given (both in the problem description and in the test data) is valid, i.e. it can be uniquely segmented using the above rules.
Now, let a string S be segmented into k syllables: \(S'_1, S'_2, \dots, S'_k\). Similarly, let another string T be segmented into m syllables: \(T'_1, T'_2, \dots, T'_m\). We say that S contains T if there exists a positive integer \(p\) (with \(p+m-1\le k\)) such that for every integer \(i\) from \(p\) to \(p+m-1\), we have \(S'_i = T'_{i-p+1}\).
For a particular idiom, there are \(n\) fixed substrings (each of length at most 10) associated with it. A string is said to be an instance of this idiom if and only if it contains exactly one occurrence of one of these fixed substrings (when compared by their syllable segmentation).
For example:
- If the only fixed substring is
ao
, then the stringnao
is not an instance of the idiom because its syllable segmentation isna, o
which does not match the segmentation ofao
(a, o
). - If the fixed substrings are
desu
andsuma
, then:kyuusaidesu
is an instance (it containsdesu
exactly once),kyuusaidesuma
andkyuusaidema
are not.
Your task is: Given \(n\) fixed substrings (each of length at most 10) corresponding to an idiom and \(q\) query strings, determine for each query string whether it is an instance of the idiom. In other words, after segmenting both the query string and each fixed substring into syllables, count the total number of occurrences (as contiguous subsequences) among all fixed substrings. If the total occurrence count is exactly 1, output YES
; otherwise, output NO
.
inputFormat
The input begins with an integer n
(the number of fixed substrings for the idiom).
The next n
lines each contain one fixed substring.
The following line contains an integer q
(the number of query strings).
Then, q
lines follow; each line contains a query string.
All strings (both fixed substrings and query strings) are non-empty and valid according to the syllable rules described above.
outputFormat
For each query string, output a single line containing YES
if the string is an instance of the idiom (i.e. if it contains exactly one occurrence of one of the fixed substrings by syllable segmentation), or NO
otherwise.
sample
1
ao
2
nao
ao
NO
YES
</p>