QOJ.ac

QOJ

実行時間制限: 5 s メモリ制限: 512 MB 満点: 100

#3314. 最短公共非子序列

統計

序列 $P$ 的子序列是指从原始序列 $P$ 中删除零个或多个元素,且保持剩余元素相对顺序所得到的序列。例如,“ICPC” 是 “MICROPROCESSOR” 的一个子序列。

两个序列的公共子序列是指同时为这两个序列的子序列的序列。著名的最长公共子序列问题旨在寻找两个给定序列的最长公共子序列。

在本题中,我们反其道而行之,考虑最短公共非子序列问题:给定两个仅由 0 和 1 组成的序列,你的任务是找到一个同样仅由 0 和 1 组成的最短序列,使得该序列不是这两个给定序列中任何一个的子序列。

输入格式

输入包含单个测试用例,共两行。两行均为仅由 0 和 1 组成的序列。它们的长度均在 1 到 4000 之间(含边界)。

输出格式

输出一行,表示两个给定序列的最短公共非子序列。如果存在多个这样的序列,请输出字典序最小的一个。在此,对于两个等长的序列 $P$ 和 $Q$,如果存在 $k$ 使得 $P_1 = Q_1, \dots, P_{k-1} = Q_{k-1}$ 且 $P_k < Q_k$(其中 $S_i$ 表示序列 $S$ 的第 $i$ 个字符),则称序列 $P$ 字典序小于序列 $Q$。

样例

样例输入 1

0101
1100001

样例输出 1

0010

样例输入 2

101010101
010101010

样例输出 2

000000

样例输入 3

11111111
00000000

样例输出 3

01

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.