2024
InterviewTime limit1sMemory limit1024 MB
Decide whether a digit string can be built from English digit words, where each word is either a digit or a repeat count for the next word's digit.
- Level
Medium5 of 10
- Topics
- Dynamic programming, String
- Solved
- No attempts yet
Problem
Pierluigi has just opened the million-dollar question on the most famous quiz show. The question is a sequence of English words, and each word stands for one of the digits zero through nine. The first offered answer is a sequence of digits. An answer makes sense if it can be obtained from the word sequence. In that process, a word either represents a digit, or it gives the number of consecutive times the digit represented by the next word appears.
The example in the picture has all answers making sense. For instance, 2024 makes sense if "Two" represents 2, "Zero" represents 0, "Two" represents 2, and "Four" represents 4. The answer 0044 also makes sense: "Two" says that the digit 0, represented by "Zero", appears twice, and then "Two" says that the digit 4, represented by "Four", appears twice. The answer 24 also makes sense. "Two" represents 2, then "Zero" says that the digit represented by the next word appears zero times, and "Four" represents 4 once. The answer 02024 does not make sense, because a count can only affect the digit represented by the next word, so the digits "02" cannot be repeated twice.
Pierluigi is not sure whether the first offered answer makes sense. Luckily, you are his lifeline.
Input
The first line contains a natural number (), the number from the problem statement.
The second line contains English words, each digit word. Each word is one of "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", and "Nine".
The third line contains a natural number (), the number from the problem statement.
The fourth line contains an -digit number, which may have leading zeros.
Output
If the answer makes sense, print "DA". Otherwise, print "NE".