QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 512 MB 总分: 100

#12535. 二进制代码

统计

Ben 最近刚学习了二进制前缀码。二进制码是一组 $n$ 个不同的非空码字 $s_i$,每个码字由 0 和 1 组成。如果对于任意 $i \neq j$,既没有 $s_i$ 是 $s_j$ 的前缀,也没有 $s_j$ 是 $s_i$ 的前缀,则称该码为前缀码。如果存在一个可能为空的字 $y$,使得 $xy = w$,则称字 $x$ 为字 $w$ 的前缀。例如,$x = 11$ 是 $w = 110$ 的前缀,$x = 0100$ 是 $w = 0100$ 的前缀。

Ben 找到了一张写有 $n$ 行二进制码的纸。然而,这张纸年代久远,上面有一些无法辨认的字符。幸运的是,每个码字中最多包含一个无法辨认的字符。

Ben 想知道这 $n$ 行是否可能表示一个二进制前缀码。换句话说,他能否将每个无法辨认的字符替换为 0 或 1,使得该编码成为前缀码?

输入格式

第一行包含整数 $n$ —— 码字的数量 ($1 \le n \le 5 \cdot 10^5$)。

接下来的 $n$ 行包含非空码字记录,每行一个。每个码字记录由 “0”、“1” 和 “?” 字符组成。每个码字记录最多包含一个代表无法辨认字符的 “?” 字符。

所有码字的总长度不超过 $5 \cdot 10^5$。

输出格式

如果该编码不能成为前缀码,则在第一行输出 “NO”。

否则,在第一行输出 “YES”。接下来的 $n$ 行应包含与输入中相应码字记录顺序相同的码字。

如果存在多种可能写在纸上的前缀码,输出其中任意一种即可。

样例

输入 1

4
00?
0?00
?1
1?0

输出 1

YES
000
0100
11
100

输入 2

3
0100
01?0
01?0

输出 2

NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.