CF510C.Fox And Names

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order.

After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted in lexicographical order in normal sense. But it was always true that after some modification of the order of letters in alphabet, the order of authors becomes lexicographical!

She wants to know, if there exists an order of letters in Latin alphabet such that the names on the paper she is submitting are following in the lexicographical order. If so, you should find out any such order.

Lexicographical order is defined in following way. When we compare s and t, first we find the leftmost position with differing characters: s__i ≠ t__i. If there is no such position (i. e. s is a prefix of t or vice versa) the shortest string is less. Otherwise, we compare characters s__i and t__i according to their order in alphabet.

Fox Ciel 即将在 FOCS(Foxes Operated Computer Systems,读作 “Fox”)会议上发表一篇论文。她听闻一个传言:论文的作者列表总是按字典序排列的。

在查阅了一些实例后,她发现该传言并不总是成立。某些论文中作者姓名并未按通常意义下的字典序排列。但她发现,总存在一种对拉丁字母表中字母顺序的重新定义,使得作者姓名列表在此新字母序下恰好构成字典序!

她希望知道:是否存在一种拉丁字母表中字母的排列顺序,使得她即将提交的这篇论文的作者姓名列表在此顺序下严格满足字典序?如果存在,请给出任意一种满足条件的字母顺序。

字典序的定义如下:比较两个字符串 ss 和 tt 时,首先找出最左侧满足 si≠tis_i \ne t_i 的位置 ii;若不存在这样的位置(即 ss 是 tt 的前缀,或反之),则较短的字符串更小;否则,根据所定义的字母表顺序比较字符 sis_i 和 tit_i。

输入格式

The first line contains an integer n (1 ≤ n ≤ 100): number of names.

Each of the following n lines contain one string name__i (1 ≤ |name__i| ≤ 100), the i-th name. Each name contains only lowercase Latin letters. All names are different.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100):名字的数量。

接下来的 nn 行,每行包含一个字符串 nameiname_i(1≤∣namei∣≤1001 \leq |name_i| \leq 100),表示第 ii 个名字。每个名字仅由小写拉丁字母组成。所有名字互不相同。

输出格式

If there exists such order of letters that the given names are sorted lexicographically, output any such order as a permutation of characters 'a'–'z' (i. e. first output the first letter of the modified alphabet, then the second, and so on).

Otherwise output a single word "Impossible" (without quotes).

如果存在一种字母顺序,使得给定的名字按字典序排列,则输出任意一种满足条件的字母顺序,表示为字符 'a'–'z' 的一个排列(即首先输出新字母表中的第一个字母,然后是第二个,依此类推)。

否则,仅输出一个单词 "Impossible"(不带引号)。

输入输出样例

  • 输入#1

    3
    rivest
    shamir
    adleman

    输出#1

    bcdefghijklmnopqrsatuvwxyz
  • 输入#2

    10
    tourist
    petr
    wjmzbmr
    yeputons
    vepifanov
    scottwu
    oooooooooooooooo
    subscriber
    rowdark
    tankengineer

    输出#2

    Impossible
  • 输入#3

    10
    petr
    egor
    endagorion
    feferivan
    ilovetanyaromanova
    kostka
    dmitriyh
    maratsnowbear
    bredorjaguarturnik
    cgyforever

    输出#3

    aghjlnopefikdmbcqrstuvwxyz
  • 输入#4

    7
    car
    care
    careful
    carefully
    becarefuldontforgetsomething
    otherwiseyouwillbehacked
    goodluck

    输出#4

    acbdefhijklmnogpqrstuvwxyz

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

首页