codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

448B.md (2653B)


      1 Source: https://codeforces.com/problemset/problem/448/B
      2 
      3 B. Suffix Structures
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
     22 
     23 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.
     24 
     25 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.
     26 
     27 Input
     28 
     29 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.
     30 
     31 Output
     32 
     33 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.
     34 
     35 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.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 automaton  
     43 tomat
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 automaton
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 array  
     56 arary
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 array
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 both  
     69 hot
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 both
     76 ```
     77 
     78 Input
     79 
     80 ```
     81 need  
     82 tree
     83 ```
     84 
     85 Output
     86 
     87 ```
     88 need tree
     89 ```
     90 
     91 Note
     92 
     93 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".