#P6965. [NEERC 2016] Binary Code
[NEERC 2016] Binary Code
题目描述
Ben has recently learned about binary prefix codes. A binary code is a set of distinct nonempty code words , each consisting of 0s and A code is called a prefix code if for every neither is a prefix of nor is a prefix of . A word is called a prefix of a word if there exists a possibly empty word , such that xy . For example, is a prefix of and is a prefix of .
Ben found a paper with lines of binary code in it. However, this paper is pretty old and there are some unreadable characters. Fortunately, each word contains at most one unreadable character.
Ben wants to know whether these lines could represent a binary prefix code. In other words, can he replace every unreadable character with or , so that the code becomes a prefix code?
输入格式
The first line contains integer -- the number of code words
Next lines contain nonempty code word records, one per line. Each code word record consists of 0, 1 and ? characters. Every code word record contains at most one ? character that represents unreadable character.
The total length of words does not exceed .
输出格式
Output NO in the first line if the code cannot be a prefix code.
Otherwise, output YES in the first line. Next lines shall contain code words in the same order as the corresponding code word records in the input.
If there are several prefix codes, that could have been written on the paper, output any one.
4
00?
0?00
?1
1?0
YES
000
0100
11
100
3
0100
01?0
01?0
NO
提示
Time limit: 2 s, Memory limit: 2048 MB.