A8349 | Brevity is Soul of Wit
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
输出格式
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.
输入输出样例
输入 #1
6 privet spasibo codeforces java marmelad normalno
输出 #1
pret sps cdfs java mama norm
输入 #2
5 aaa aa a aaaa aaaaa
输出 #2
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted