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

B. Suffix Structures
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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),s and t. You need to transform words 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.

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 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 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 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.

Sample test(s)
Input
automaton
tomat
Output
automaton
Input
array
arary
Output
array
Input
both
hot
Output
both
Input
need
tree
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 automaton and then make two swaps of the string using the suffix array and get "hot".


题意:两个字符串s和t,如果s通过删除字符得到t输出automaton,如果s通过交换顺序得到t输出array,如果两个都用到了,输出both


思路:直接一顿乱搞就好了,只要注意检查t是否能存在于s中就行了。



ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
using namespace std;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head
char s1[MAXN],s2[MAXN];
int num1[26],num2[26];
int main()
{
	int i;
	while(scanf("%s%s",s1,s2)!=EOF)
	{
		int len1=strlen(s1);
		int len2=strlen(s2);
		mem(num1);mem(num2);
		for(i=0;i<len1;i++)
		num1[s1[i]-'a']++;
		for(i=0;i<len2;i++)
		num2[s2[i]-'a']++;
		int bz=0;
		for(i=0;i<26;i++)
		if(num1[i]<num2[i])
		{
			bz=1;
			break;
		}
		if(bz)
		printf("need tree\n");
		else
		{
			int flag=0;
			for(i=0;i<26;i++)
			{
				if(num1[i]==num2[i])
				continue;
				if(num1[i]>num2[i])
				flag=1;
			}
			if(flag)
			{
				int j=0;
				for(i=0;i<len1;i++)
				{
					if(s1[i]==s2[j])
					{
						j++;
						if(j==len2)
						{
							bz=1;
							break;
						}
					}
				}
				if(bz)
				printf("automaton\n");
				else
				printf("both\n");
			}
			else
			printf("array\n");
		}
	}
	return 0;
}


你可能感兴趣的:(round,codeforces,#25)