#P3025. [USACO11OPEN] Forgotten Password S
[USACO11OPEN] Forgotten Password S
Description
As often happens to us, Bessie has once again forgotten her barn manager password. She can only remember part of it.
First, she remembers that the password is a string of length (), and that the password is formed by concatenating one or more words, each of which is recorded in her dictionary of () words. Every dictionary word consists of to lowercase Latin letters.
She only remembers some letters in the password and their positions. For example, Bessie remembers her password as a??l?ban???????, where ? stands for a letter she forgot. Her dictionary contains these words: apple cow farmer banana bananas pies. Therefore, two possible passwords for Bessie are applebananapies and applebananascow.
Now, given the letters Bessie still remembers and her dictionary, find a possible password. If there are multiple answers, output the lexicographically smallest one.
Input Format
The first line contains the length of her password and the number of words in the dictionary, separated by a space.
The second line contains the string of length .
Then follow lines, each containing a string .
Output Format
Output exactly one line: Bessie’s password.
15 6
a??l?ban???????
apple
cow
farmer
banana
bananas
pies
applebananapies
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号