Codeforces Round #256 (Div. 2) B. Suffix Structures

Source: Internet
Author: User
Tags first string

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, distinct words (strings of Chinese 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-a string, he can remove from the this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, the he can swap any of the characters of this string. The guys does not know anything is about the suffix tree, but it can help them does much more.

Bizon the Champion wonders whether the "bizons" can solve the problem. Perhaps, the solution does not require both data structures. Find out whether the guys can solve the problem and if they can, how does they do it? Can they solve it either only with the use of the suffix automaton or only with the use of suffix array or they need both structures? Note that any structure is used a unlimited number of times, the structures may is used in any order.

Input

The first line contains a non-empty word s. The second line contains a non-empty wordt. Words s andT are different. Each word consists only of lowercase 中文版 letters. Each of the word contains at the most letters.

Output

The answer to the problem. Print "Need tree" (without the quotes) if Words 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 so if you can solve the problem only with use of the suffix array and then it's impossible to solve it's only WI th use of suffix automaton. This is also true for suffix automaton.

Sample Test (s) Input
Automatontomat
Output
Automaton
Input
Arrayarary
Output
Array
Input
Bothhot
Output
Both
Input
Needtree
Output
Need tree topic: given two strings, if string 2 can be removed by string 1 to get a number of characters, the output automaton, if the string 1 can change the order of the input array, two are used for both, otherwise need The main technique of tree is to judge the situation except the first.
#include <iostream> #include <cstring> #include <cstdio> #include <string> #include <cmath > #include <algorithm> #define LL int#define inf 0x3f3f3f3fusing namespace Std;char a[101],b[101];bool bj[1000];    int main () {LL n,m,i,j,k,l1,l2;        while (scanf ("%s", a)!=eof) {bool Vis=false;        scanf ("%s", b);        L1=strlen (a); L2=strlen (b);        k=0;            for (i=0;i<l1;i++) {if (a[i]==b[k]) k++;                if (b[k]== ') {vis=true;            Break            }} if (Vis) {printf ("automaton\n");        Continue         } memset (Bj,false,sizeof (BJ));        k=0; for (i=0;i<l2;i++) {for (j=0;j<l1;j++)//The first string is placed in the inner layer, mainly on the string 1 operation to get the string 2 {if (!                BJ[J])//After comparison and the same matching characters are marked down.                        {if (A[j]==b[i]) {k++; Bj[j]=true;                    Break            }}}} if (K==L2)//If the number of tokens in string 1 and string 2 is the same, the following 2 cases {if (L1==L2)            {printf ("array\n");        } else printf ("both\n");    } else<span id= "Transmark" ></span> printf ("Need tree\n"); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces Round #256 (Div. 2) B. Suffix Structures

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.