欢迎光临散文网 会员登陆 & 注册

CF 1744A - Number Replacement

2023-08-18 17:01 作者:您是打尖儿还是住店呢  | 我要投稿

An integer array a1,a2,…,an is being transformed into an array of lowercase English letters using the following prodecure:

While there is at least one number in the array:

Choose any number x from the array a, and any letter of the English alphabet y.

Replace all occurrences of number x with the letter y.

For example, if we initially had an array a=[2,3,2,4,1], then we could transform it the following way:

Choose the number 2 and the letter c. After that a=[c,3,c,4,1].

Choose the number 3 and the letter a. After that a=[c,a,c,4,1].

Choose the number 4 and the letter t. After that a=[c,a,c,t,1].

Choose the number 1 and the letter a. After that a=[c,a,c,t,a].

After the transformation all letters are united into a string, in our example we get the string "cacta".

Having the array a and the string s determine if the string s could be got from the array a after the described transformation?

Input

The first line contains a single integer t (1≤t≤103) — the number of test cases.

Then the description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤50) — the length of the array a and the string s.

The second line of each test case contains exactly n integers: a1,a2,…,an (1≤ai≤50) — the elements of the array a.

The third line of each test case contains a string s of length n, consisting of lowercase English letters.

Output

For each test case, output "YES", if we can get the string s from the array a, and "NO" otherwise. You can output each letter in any case.

-----------------------------------------

使用以下过程将整数数组 a1,a2,…,an 转换为小写英文字母数组:

虽然数组中至少有一个数字:

从数组 a 中选择任意数字 x 和英文字母 y 中的任意字母。

将所有出现的数字 x 替换为字母 y。

例如,如果我们最初有一个数组 a=[2,3,2,4,1],那么我们可以按以下方式对其进行转换:

选择数字 2 和字母 c。 之后a=[c,3,c,4,1]。

选择数字 3 和字母 a。 之后a=[c,a,c,4,1]。

选择数字 4 和字母 t。 之后a=[c,a,c,t,1]。

选择数字 1 和字母 a。 之后a=[c,a,c,t,a]。

转换后,所有字母都统一为一个字符串,在我们的示例中,我们得到字符串“cacta”。

让数组a和字符串s确定在所描述的转换之后是否可以从数组a中得到字符串s?

输入

第一行包含一个整数 t (1≤t≤103) — 测试用例的数量。

然后是测试用例的描述。

每个测试用例的第一行包含一个整数 n (1≤n≤50) — 数组 a 和字符串 s 的长度。

每个测试用例的第二行恰好包含 n 个整数:a1,a2,…,an (1≤ai≤50) — 数组 a 的元素。

每个测试用例的第三行包含一个长度为n的字符串s,由小写英文字母组成。

输出

对于每个测试用例,如果我们可以从数组 a 中获取字符串 s,则输出“YES”,否则输出“NO”。 您可以在任何情况下输出每个字母。

--------------------------------

同样用hashmap即可;

下面是代码:


CF 1744A - Number Replacement的评论 (共 条)

分享到微博请遵守国家法律