CF1422E.Minlexes

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Some time ago Lesha found an entertaining string ss consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows.

Lesha chooses an arbitrary (possibly zero) number of pairs on positions (i,i+1)(i, i + 1) in such a way that the following conditions are satisfied:

  • for each pair (i,i+1)(i, i + 1) the inequality 0≤i<∣s∣−10 \le i \lt |s| - 1 holds;
  • for each pair (i,i+1)(i, i + 1) the equality si=si+1s_i = s_{i + 1} holds;
  • there is no index that is contained in more than one pair.

After that Lesha removes all characters on indexes contained in these pairs and the algorithm is over.

Lesha is interested in the lexicographically smallest strings he can obtain by applying the algorithm to the suffixes of the given string.

不久之前,Lesha 发现了一个由小写英文字母组成的有趣字符串 ss。Lesha 立即为该字符串设计了一种独特的算法,并与你分享。该算法步骤如下:

Lesha 任意选择若干对位置 (i,i+1)(i, i + 1)(可选零对),使得满足以下条件:

  • 对于每一对 (i,i+1)(i, i + 1),不等式 0≤i<∣s∣−10 \le i \lt |s| - 1 成立;
  • 对于每一对 (i,i+1)(i, i + 1),等式 si=si+1s_i = s_{i + 1} 成立;
  • 任意下标至多属于其中一对。

随后,Lesha 删除所有位于这些对中所含下标处的字符,算法即结束。

Lesha 感兴趣的是:对给定字符串的所有后缀应用该算法后,所能得到的字典序最小的字符串。

输入格式

The only line contains the string ss (1≤∣s∣≤1051 \le |s| \le 10^5) — the initial string consisting of lowercase English letters only.

仅一行,包含字符串 ss(1≤∣s∣≤1051 \le |s| \le 10^5)——由小写英文字母组成的初始字符串。

输出格式

In ∣s∣|s| lines print the lengths of the answers and the answers themselves, starting with the answer for the longest suffix. The output can be large, so, when some answer is longer than 1010 characters, instead print the first 55 characters, then "...", then the last 22 characters of the answer.

在 ∣s∣|s| 行中输出各答案的长度及答案本身,首先输出对应最长后缀的答案。输出可能很大,因此当某个答案的长度超过 1010 个字符时,请仅输出该答案的前 55 个字符,然后输出 ...,最后输出该答案的最后 22 个字符。

输入输出样例

  • 输入#1

    abcdd

    输出#1

    3 abc
    2 bc
    1 c
    0 
    1 d
  • 输入#2

    abbcdddeaaffdfouurtytwoo

    输出#2

    18 abbcd...tw
    17 bbcdd...tw
    16 bcddd...tw
    15 cddde...tw
    14 dddea...tw
    13 ddeaa...tw
    12 deaad...tw
    11 eaadf...tw
    10 aadfortytw
    9 adfortytw
    8 dfortytw
    9 fdfortytw
    8 dfortytw
    7 fortytw
    6 ortytw
    5 rtytw
    6 urtytw
    5 rtytw
    4 tytw
    3 ytw
    2 tw
    1 w
    0 
    1 o

说明/提示

Consider the first example.

  • The longest suffix is the whole string "abcdd". Choosing one pair (4,5)(4, 5), Lesha obtains "abc".
  • The next longest suffix is "bcdd". Choosing one pair (3,4)(3, 4), we obtain "bc".
  • The next longest suffix is "cdd". Choosing one pair (2,3)(2, 3), we obtain "c".
  • The next longest suffix is "dd". Choosing one pair (1,2)(1, 2), we obtain "" (an empty string).
  • The last suffix is the string "d". No pair can be chosen, so the answer is "d".

In the second example, for the longest suffix "abbcdddeaaffdfouurtytwoo" choose three pairs (11,12)(11, 12), (16,17)(16, 17), (23,24)(23, 24) and we obtain "abbcdddeaadfortytw"

考虑第一个例子。

  • 最长的后缀是整个字符串 "abcdd"。选择一对下标 (4,5)(4, 5),Lesha 得到 "abc"。
  • 次长的后缀是 "bcdd"。选择一对下标 (3,4)(3, 4),我们得到 "bc"。
  • 再次长的后缀是 "cdd"。选择一对下标 (2,3)(2, 3),我们得到 "c"。
  • 再次长的后缀是 "dd"。选择一对下标 (1,2)(1, 2),我们得到 ""(空字符串)。
  • 最后一个后缀是字符串 "d"。无法选择任何一对下标,因此答案为 "d"。

在第二个例子中,对于最长的后缀 "abbcdddeaaffdfouurtytwoo",选择三对下标 (11,12)(11, 12)、(16,17)(16, 17) 和 (23,24)(23, 24),我们得到 "abbcdddeaadfortytw"。

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

首页