CF988B.Substrings Sort

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.

String aa is a substring of string bb if it is possible to choose several consecutive letters in bb in such a way that they form aa. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof".

给你 nn 个字符串,每个字符串均由小写英文字母组成。请重新排列(重排序)这些字符串,使得对每个字符串而言,排在其前面的所有字符串都是它的子串。

若字符串 aa 可通过选取字符串 bb 中若干连续的字母而构成,则称 aa 是 bb 的子串。例如,字符串 "for" 是字符串 "codeforces"、"for" 和 "therefore" 的子串,但不是字符串 "four"、"fofo" 和 "rof" 的子串。

输入格式

The first line contains an integer nn (1≤n≤1001 \le n \le 100) — the number of strings.

The next nn lines contain the given strings. The number of letters in each string is from 11 to 100100, inclusive. Each string consists of lowercase English letters.

Some strings might be equal.

第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 字符串的数量。

接下来的 nn 行包含给定的字符串。每个字符串的字母数量在 11 到 100100 之间(含端点)。每个字符串均由小写英文字母组成。

某些字符串可能相等。

输出格式

If it is impossible to reorder nn given strings in required order, print "NO" (without quotes).

Otherwise print "YES" (without quotes) and nn given strings in required order.

如果无法将给定的 nn 个字符串重新排列成所要求的顺序,则输出 "NO"(不带引号)。

否则,输出 "YES"(不带引号),并在下一行输出按所要求顺序排列的 nn 个给定字符串。

输入输出样例

  • 输入#1

    5
    a
    aba
    abacaba
    ba
    aba

    输出#1

    YES
    a
    ba
    aba
    aba
    abacaba
  • 输入#2

    5
    a
    abacaba
    ba
    aba
    abab

    输出#2

    NO
  • 输入#3

    3
    qwerty
    qwerty
    qwerty

    输出#3

    YES
    qwerty
    qwerty
    qwerty

说明/提示

In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".

在第二个例子中,您不能重新排列这些字符串,因为字符串 “abab” 不是字符串 “abacaba” 的子串。

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

首页