P3065 [USACO12DEC] First! G
题目描述
Bessie has been playing with strings again. She found that by
changing the order of the alphabet she could make some strings come before all the others lexicographically (dictionary ordering).
For instance Bessie found that for the strings "omm", "moo", "mom", and "ommnom" she could make "mom" appear first using the standard alphabet and that she could make "omm" appear first using the alphabet
"abcdefghijklonmpqrstuvwxyz". However, Bessie couldn't figure out any way to make "moo" or "ommnom" appear first.
Help Bessie by computing which strings in the input could be
lexicographically first by rearranging the order of the alphabet. To compute if string X is lexicographically before string Y find the index of the first character in which they differ, j. If no such index exists then X is lexicographically before Y if X is shorter than Y. Otherwise X is lexicographically before Y if X[j] occurs earlier in the alphabet than Y[j].
Bessie 一直在研究字符串。她发现,通过改变字母表的顺序,她可以按改变后的字母表来排列字符串(字典序大小排列)。
例如,Bessie 发现,对于字符串 $\texttt{omm},\texttt{moo},\texttt{mom}$ 和 $\texttt{ommnom}$,她可以使用标准字母表使 $\texttt{mom}$ 排在第一个(即字典序最小),她也可以使用字母表 $\texttt{abcdefghijklonmpqrstuvwxyz}$ 使得 $\texttt{omm}$ 排在第一个。然而,Bessie 想不出任何方法(改变字母表顺序)使得 $\texttt{moo}$ 或 $\texttt{ommnom}$ 排在第一个。
接下来让我们通过重新排列字母表的顺序来计算输入中有哪些字符串可以排在第一个(即字典序最小),从而帮助 Bessie。
要计算字符串 $X$ 和字符串 $Y$ 按照重新排列过的字母表顺序来排列的顺序,先找到它们第一个不同的字母 $X_i$ 与 $Y_i$,按重排后的字母表顺序比较,若 $X_i$ 比 $Y_i$ 先,则 $X$ 的字典序比 $Y$ 小,即 $X$ 排在 $Y$ 前;若没有不同的字母,则比较 $X$ 与 $Y$ 长度,若 $X$ 比 $Y$ 短,则 $X$ 的字典序比 $Y$ 小,即 $X$ 排在 $Y$ 前。
输入格式
无
输出格式
无
说明/提示
The example from the problem statement.
Only "omm" and "mom" can be ordered first.
样例即题目描述中给出的例子,只有 $\texttt{omm}$ 和 $\texttt{mom}$ 在各自特定的字典序下可以被排列在第一个。