CF448B.Suffix Structures
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.
冠军野牛比松不仅仅是一头野牛,他还是“比松队”的宠儿。
在一次竞赛中,“比松队”收到了如下题目:“给定两个不同的单词(由英文字母组成的字符串)s 和 t,你需要将单词 s 变换为单词 t。” 这道题看起来很简单,因为队员们对后缀数据结构非常熟悉。资深比松钟爱后缀自动机:对一个字符串应用一次后缀自动机,可以从中删除任意一个字符。中年比松精通后缀数组:对一个字符串应用一次后缀数组,可以交换该字符串中任意两个字符。队员们对后缀树一无所知,但后缀树实际上能帮他们完成更多操作。
冠军比松想知道:“比松队”能否解决这个问题?也许该问题的解法并不需要同时使用这两种数据结构。请判断队员们是否能解决该问题;若能,他们应如何操作?他们能否仅使用后缀自动机、或仅使用后缀数组、抑或必须同时使用两种结构?注意:每种结构均可被使用任意多次,且可按任意顺序使用。
输入格式
The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
第一行包含一个非空单词 s。第二行包含一个非空单词 t。单词 s 和 t 不相同。每个单词仅由小写英文字母组成。每个单词最多包含 100 个字母。
输出格式
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word t even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.
在单行中输出问题的答案。如果单词 s 即使同时使用后缀数组(suffix array)和后缀自动机(suffix automaton)也无法转换为单词 t,则输出 need tree(不带引号)。如果仅需后缀自动机即可解决该问题,则输出 automaton(不带引号)。如果仅需后缀数组即可解决该问题,则输出 array(不带引号)。如果需要同时使用这两种数据结构才能解决该问题,则输出 both(不带引号)。
题目保证:若该问题仅用后缀数组即可解决,则它一定无法仅用后缀自动机解决;反之,若该问题仅用后缀自动机即可解决,则它一定无法仅用后缀数组解决。
输入输出样例
输入#1
automaton tomat
输出#1
automaton
输入#2
array arary
输出#2
array
输入#3
both hot
输出#3
both
输入#4
need tree
输出#4
need tree
说明/提示
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".
在第三个样例中,你可以这样操作:首先利用后缀自动机删除第一个字符,将 "both" 变为 "oth";然后利用后缀数组对字符串进行两次交换,得到 "hot"。
输入解题思路,AI测评打分。不知道怎么写?