eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Periodic, My Dear Watson

Periodic, My Dear Watson

Given the periodic table and a series of words, determine whether the word can be formed using the elements in the periodic table. If there are multiple ways of doing so, select the one with the fewest number of required elements. If multiple options use the same minimal number of elements, sum the atomic numbers (atomic numbers are implied by the order in which the elements are read in) used for each option, and select the one with the smallest value. If there are still multiple, then there's probably no point, as it is most likely too obvious, so in these cases, simply print "\textbf{Too Obvious}" for the given word. An '\textbf{element}' always starts with a capital letter followed by zero or more lower case letters. \InputFile Input will begin with a line containing a single integer, \textbf{N} representing the number of cases to process. Each case will being with a line with a single integer, \textbf{O}, representing the number of symbols in the case. The next \textbf{O} lines will contain one element per line. The next line will contain a single integer, \textbf{P} representing the number of words to process in this case. The next \textbf{P} lines contain one word each. \textbf{O} and \textbf{P} as well as the length of any element or name will be less than \textbf{5000}. \OutputFile If a given word has a deterministic answer based on the periodic table provided and the above stated rules, print the case number and the series of elements used, forming the word, but with square brackets around them to indicate the elements. One example output line might be: "\textbf{\[Ba\]\[Na\]\[Na\]}".
Лимит времени 3 секунды
Лимит использования памяти 256 MiB
Входные данные #1
14
Ba
Na
NA2
banana
nan
Выходные данные #1
[Ba][Na][Na]
[Na][N]
Источник ACM ICPC North America - South Central USA 2011