Codeforces round #256 (Div. 2) B. suffix structures (simulation)

Source: Internet
Author: User

Link: http://codeforces.com/contest/448/problem/ B


----------------------------------------------------------------------------------------------------------------------------------------------------------
Welcome to tianci Hut: http://user.qzone.qq.com/593830943/main
 
----------------------------------------------------------------------------------------------------------------------------------------------------------


B. suffix structurestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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 ),SAndT. You need to transform wordSInto WORDT". The task looked simple to the guys because they know the suffix data structures well. bizon senior loves suffix automatic. 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.

Input

The first line contains a non-empty wordS. The second line contains a non-empty wordT. WordsSAndTAre different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.

Output

In the single line print the answer to the problem. Print "need Tree" (without the quotes) If wordSCannot be transformed into WORDTEven with use of both suffix array and suffix automation. print "Automaton" (without the quotes) If you need only the suffix automation 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 automation. This is also true for suffix automation.

Sample test (s) Input
automatontomat
Output
automaton
Input
arrayarary
Output
array
Input
bothhot
Output
both
Input
needtree
Output
need tree
Note

In the third sample you can act like that: first transform "both" into "Oth" by removing the first character using the suffix automatic on and then make two swaps of the string using the suffix array and get "hot ".


The Code is as follows:

# Include <iostream >#include <algorithm> using namespace STD; # define n 47 # define M 100000 # include <cstring> int A [n], B [N]; char s [M + 17], t [M + 17]; void Init () {memset (A, 0, sizeof (a); memset (B, 0, sizeof (B);} int main () {int I, j; while (CIN> S) {Init (); CIN> T; int lens = strlen (s); int lent = strlen (t); for (I = 0; I <lens; I ++) {A [s [I]-'a'] ++;} for (I = 0; I <lent; I ++) {B [T [I]-'a'] ++;} int flag = 0; If (lens <lent ){ Flag = 1 ;}for (I = 0; I <26; I ++) {if (a [I] <B [I]) {flag = 1; break ;}}if (flag = 1) {cout <"need Tree" <Endl; continue;} If (lens = lent) {cout <"array" <Endl; continue;} int p = 0, j = 0; for (I = 0; I <lent; I ++) {While (T [I]! = S [J] & J <lens) {J ++;} If (j> = Lens) // It indicates that the t can be formed in the order of not exchanging s substrings {p = 1; break;} J ++;} If (P = 1) {cout <"both" <Endl; continue;} cout <"Automaton" <Endl;} return 0 ;}



Codeforces round #256 (Div. 2) B. suffix structures (simulation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.