#P6286. [COCI 2016/2017 #1] Cezar
[COCI 2016/2017 #1] Cezar
Problem Description
Mirko wants to encrypt words. The encryption works as follows:
- Choose a permutation of the English alphabet as the key.
- Replace
awith the first letter of the key, replacebwith the second letter of the key, and so on.
For example, using qwertyuiopasdfghjklzxcvbnm as the key to encrypt cezar yields etmqk.
He hopes that, after encrypting all words and sorting them in ascending lexicographical order, the original -th word will be in position . Determine whether this can be achieved. If it can, output any feasible key.
Input Format
The first line contains an integer .
The next lines each contain a string, representing a word to be encrypted.
The last line contains integers, representing .
Output Format
This problem uses Special Judge.
If Mirko's requirement cannot be satisfied, output NE.
Otherwise, output DA. Then output one more line with any feasible key.
2
ab
bc
2 1
DA
bacdefghijklmnopqrstuvwxyz
3
abc
bcd
add
1 2 3
NE
3
bbb
ccc
ddd
2 3 1
DA
adbcefghijklmnopqrstuvwxyz
Hint
Sample Explanation
Sample 1 Explanation
Using bacdefghijklmnopqrstuvwxyz as the key, we get:
baac
After sorting in ascending lexicographical order, we get:
acba
The original first word is in position 2, and the original second word is in position 1. This meets the requirement.
Sample 3 Explanation
Using adbcefghijklmnopqrstuvwxyz as the key, we get:
dddbbbccc
After sorting in ascending lexicographical order, we get:
bbbdddccc
The original first word is in position 2, the original second word is in position 3, and the original third word is in position 1. This meets the requirement.
Constraints
For of the testdata, , .
The length of each word is at most , and each word contains only lowercase letters.
Notes
This problem is translated from COCI2016-2017 CONTEST #1 T3 Cezar。
Translated by ChatGPT 5