309317: CF1662B. Toys

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Toys

题意翻译

你有一些纸,你可以在纸的正反面各写一个字母。现在你要用这些纸拼三个单词。纸的顺序可以重新排列,正反面都可以用(当然,你不能同时用一张纸的正反面)。三个单词不必同时拼出,只要保证每个单词都能拼即可。 请你求出,为了拼这三个单词,你至少需要多少纸,并给出一种可行的写字母方案。 ### 输入格式 要拼的三个单词。只包含大写字母,长度为 $1$ 至 $1000$。 ### 输出格式 一个正整数 $m$,表示需要的最少纸数。 接下来 $m$ 行,每行两个字母,表示每张纸正反面写的两个字母。 ### 说明/提示 样例一中,答案用了两张纸:第一张一面写 A,另一面写 G;第二张一面写 A,另一面写 M。 三个单词中,单词 AA 可以用两个 A 拼出,单词 GA 可以用第一张纸的 G 与第二张纸的 A 拼出,单词 MA 可以用第二张纸的 M 和第一张纸的 A 拼出。

题目描述

Vittorio has three favorite toys: a teddy bear, an owl, and a raccoon. Each of them has a name. Vittorio takes several sheets of paper and writes a letter on each side of every sheet so that it is possible to spell any of the three names by arranging some of the sheets in a row (sheets can be reordered and flipped as needed). The three names do not have to be spelled at the same time, it is sufficient that it is possible to spell each of them using all the available sheets (and the same sheet can be used to spell different names). Find the minimum number of sheets required. In addition, produce a list of sheets with minimum cardinality which can be used to spell the three names (if there are multiple answers, print any).

输入输出格式

输入格式


The first line contains a string $ t $ consisting of uppercase letters of the English alphabet ( $ 1\le |t| \le 1000 $ ) — the name of the teddy bear. The second line contains a string $ o $ consisting of uppercase letters of the English alphabet ( $ 1\le |o| \le 1000 $ ) — the name of the owl. The third line contains a string $ r $ consisting of uppercase letters of the English alphabet ( $ 1\le |r| \le 1000 $ ) — the name of the raccoon. The values $ |t| $ , $ |o| $ , $ |r| $ denote the length of the three names $ t $ , $ o $ , $ r $ .

输出格式


The first line of the output contains a single integer $ m $ — the minimum number of sheets required. Then $ m $ lines follow: the $ j $ -th of these lines contains a string of two uppercase letters of the English alphabet — the letters appearing on the two sides of the $ j $ -th sheet. Note that you can print the sheets and the two letters of each sheet in any order.

输入输出样例

输入样例 #1

AA
GA
MA

输出样例 #1

2
AG
AM

输入样例 #2

TEDDY
HEDWIG
RACCOON

输出样例 #2

8
AT
CH
CY
DG
DO
ER
IN
OW

输入样例 #3

BDC
CAA
CE

输出样例 #3

4
AD
AE
BB
CC

说明

In the first sample, the solution uses two sheets: the first sheet has A on one side and G on the other side; the second sheet has A on one side and M on the other side. The name AA can be spelled using the A side of both sheets. The name GA can be spelled using the G side of the first sheet and the A side of the second sheet. Finally, the name MA can be spelled using the M side of the second sheet and the A side of the first sheet.

Input

题意翻译

你有一些纸,你可以在纸的正反面各写一个字母。现在你要用这些纸拼三个单词。纸的顺序可以重新排列,正反面都可以用(当然,你不能同时用一张纸的正反面)。三个单词不必同时拼出,只要保证每个单词都能拼即可。 请你求出,为了拼这三个单词,你至少需要多少纸,并给出一种可行的写字母方案。 ### 输入格式 要拼的三个单词。只包含大写字母,长度为 $1$ 至 $1000$。 ### 输出格式 一个正整数 $m$,表示需要的最少纸数。 接下来 $m$ 行,每行两个字母,表示每张纸正反面写的两个字母。 ### 说明/提示 样例一中,答案用了两张纸:第一张一面写 A,另一面写 G;第二张一面写 A,另一面写 M。 三个单词中,单词 AA 可以用两个 A 拼出,单词 GA 可以用第一张纸的 G 与第二张纸的 A 拼出,单词 MA 可以用第二张纸的 M 和第一张纸的 A 拼出。

加入题单

算法标签: