Alien DictionaryProblem code: PGM6 |
All submissions for this problem are available.
Some alien civilization has a quite strange language. Each word has length wordLength and consists of only 'A' and 'B' characters. Some sequences of A's and B's are forbidden (by ancient tradition), and do not appear as a substring of any valid word. Any word that does not contain a forbidden substring is valid. The set of forbidden substrings is given in the String[] forbiddenSubstrings. Each element of forbiddenSubstrings contains 'A' or 'B' .
The alien dictionary contains all valid alien words in alphabetical order. Each page of the dictionary contains exactly one word. Pages are numbered starting from 0. Given a int[] wordNumbers, return a String[] containing the same number of elements as wordNumbers, where the i-th element is the word written on page wordNumbers[i] of the dictionary or "NO PAGE" (quotes for clarity) if there is no such page in the dictionary.
Input
The first line consists of the number of characters. This is followed by the list of forbidden substrings separated by space. The last line consists of the page numbers to be displayed.
Output
List of words in the specified pages as specified in the problem statement. NO PAGE if there is no page.
Example
Input:
5
AAA BAA ABB
4 12 0 6 9
Output:
{BBBAB,NO PAGE,AABAB,BBBBB,NO PAGE}
| Date: | 2010-02-27 |
| Time limit: | 5s |
| Source limit: | 50000 |
| Languages: | C |
Comments

Fetching successful submissions
