CF120H.Brevity is Soul of Wit

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

As we communicate, we learn much new information. However, the process of communication takes too much time. It becomes clear if we look at the words we use in our everyday speech.

We can list many simple words consisting of many letters: "information", "technologies", "university", "construction", "conservatoire", "refrigerator", "stopwatch", "windowsill", "electricity", "government" and so on. Of course, we can continue listing those words ad infinitum.

Fortunately, the solution for that problem has been found. To make our speech clear and brief, we should replace the initial words with those that resemble them but are much shorter. This idea hasn't been brought into life yet, that's why you are chosen to improve the situation.

Let's consider the following formal model of transforming words: we shall assume that one can use n words in a chat. For each words we shall introduce a notion of its shorter variant. We shall define shorter variant of an arbitrary word s as such word t, that meets the following conditions:

  • it occurs in s as a subsequence,
  • its length ranges from one to four characters.

In other words, the word t consists at least of one and at most of four characters that occur in the same order in the word s. Note that those characters do not necessarily follow in s immediately one after another. You are allowed not to shorten the initial word if its length does not exceed four characters.

You are given a list of n different words. Your task is to find a set of their shortened variants. The shortened variants of all words from the list should be different.

我们在交流过程中会学到大量新信息。然而,交流过程耗时过长。这一点,只要观察我们日常口语中所使用的单词,便一目了然。

我们可以列举出许多由大量字母构成的简单单词:“information”(信息)、“technologies”(技术)、“university”(大学)、“construction”(建筑)、“conservatoire”(音乐学院)、“refrigerator”(冰箱)、“stopwatch”(秒表)、“windowsill”(窗台)、“electricity”(电)、“government”(政府)等等。当然,这样的单词还可以无限列举下去。

幸运的是,该问题的解决方案已被找到。为了使我们的言语既清晰又简洁,我们应当将原始单词替换为那些与其形似但长度显著更短的新词。这一构想尚未付诸实践,因此你被选中来改善这一现状。

我们考虑如下单词变换的形式化模型:假设在一次聊天中可使用 nn 个单词。对每个单词,我们引入其缩略形式的概念。我们定义任意单词 ss 的缩略形式为满足以下条件的单词 tt:

  • tt 是 ss 的一个子序列(subsequence),
  • tt 的长度介于 11 至 44 个字符之间(含端点)。

换言之,单词 tt 由至少 11 个、至多 44 个字符组成,这些字符在 ss 中以相同顺序出现(但未必连续相邻)。若原始单词 ss 的长度本身不超过 44 个字符,则允许不对其进行缩略。

现给出一个包含 nn 个互不相同的单词的列表。你的任务是为这些单词找出一组缩略形式,使得列表中所有单词的缩略形式彼此互不相同。

输入格式

The first line of the input file contains the only integer n (1 ≤ n ≤ 200). Then n lines contain a set of different non-empty words that consist of lowercase Latin letters. The length of each word does not exceed 10 characters.

输入文件的第一行包含唯一一个整数 nn(1≤n≤2001 \leq n \leq 200)。接下来的 nn 行包含一组互不相同的非空单词,每个单词均由小写拉丁字母组成。每个单词的长度不超过 1010 个字符。

输出格式

If the solution exists, print in the output file exactly n lines, where the i-th line represents the shortened variant of the i-th word from the initial set. If there are several variants to solve the problem, print any of them. If there is no solution, print -1.

如果存在解,则在输出文件中恰好打印 n 行,其中第 i 行表示初始词集中第 i 个单词的缩写形式。若存在多种可行解,输出任意一种即可。若无解,则输出 -1。

输入输出样例

  • 输入#1

    6
    privet
    spasibo
    codeforces
    java
    marmelad
    normalno

    输出#1

    pret
    sps
    cdfs
    java
    mama
    norm
  • 输入#2

    5
    aaa
    aa
    a
    aaaa
    aaaaa

    输出#2

    -1

输入解题思路,AI测评打分。不知道怎么写?

首页