#P6495. [COCI 2016/2017 #2] Tavan
[COCI 2016/2017 #2] Tavan
Description
Željko is reading a letter from his grandma. Because it is very old, some words in the letter can no longer be recognized. He picked a word of length and replaced unrecognizable letters with #.
For each #, grandma provided letters, and the original letter at that position is one of these letters. Among all possible words, the -th one in lexicographical order is the original word.
Please help them find the original word.
Input Format
The first line contains four integers .
The second line contains a string of length , representing the word Željko picked.
The next lines each contain a string of length , representing the letters provided by grandma.
Output Format
One line containing a string, representing the original word.
9 2 3 7
po#olje#i
sol
znu
posoljeni
4 1 2 2
#rak
zm
zrak
Hint
Sample 1 Explanation
All possible words in lexicographical order are:
pololjenipololjeuipololjezipoooljenipoooljeuipoooljeziposoljeniposoljeuiposoljezi
The -th word is posoljeni。
Constraints
For of the testdata, , , , .
All strings contain only lowercase letters and #。
Notes
This problem is translated from COCI2016-2017 CONTEST #2 T2 Tavan。
Translated by ChatGPT 5
京公网安备 11011102002149号