CF1744A.Number Replacement

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

An integer array a1,a2,…,ana_1, a_2, \ldots, a_n 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 xx from the array aa, and any letter of the English alphabet yy.
  • Replace all occurrences of number xx with the letter yy.

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

  • Choose the number 22 and the letter c. After that a=[c,3,c,4,1]a = [c, 3, c, 4, 1].
  • Choose the number 33 and the letter a. After that a=[c,a,c,4,1]a = [c, a, c, 4, 1].
  • Choose the number 44 and the letter t. After that a=[c,a,c,t,1]a = [c, a, c, t, 1].
  • Choose the number 11 and the letter a. After that a=[c,a,c,t,a]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 aa and the string ss determine if the string ss could be got from the array aa after the described transformation?

一个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n 通过以下过程被转换为一个小写英文字母组成的数组:

只要数组中至少还存在一个数字,就执行如下操作:

  • 从数组 aa 中任选一个数字 xx,再任选一个英文字母 yy;
  • 将数组中所有等于 xx 的数字全部替换为字母 yy。

例如,若初始数组为 a=[2,3,2,4,1]a = [2, 3, 2, 4, 1],则可按如下方式变换:

  • 选择数字 22 和字母 c,变换后 a=[c,3,c,4,1]a = [c, 3, c, 4, 1];
  • 选择数字 33 和字母 a,变换后 a=[c,a,c,4,1]a = [c, a, c, 4, 1];
  • 选择数字 44 和字母 t,变换后 a=[c,a,c,t,1]a = [c, a, c, t, 1];
  • 选择数字 11 和字母 a,变换后 a=[c,a,c,t,a]a = [c, a, c, t, a]。

变换结束后,所有字母按顺序拼接成一个字符串;在本例中得到字符串 "cacta"。

给定数组 aa 和字符串 ss,请判断:字符串 ss 是否可能由数组 aa 经上述变换过程得到?

输入格式

The first line contains a single integer tt (1≤t≤103(1 \leq t \leq 10^3) — the number of test cases.

Then the description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤501 \leq n \leq 50) — the length of the array aa and the string ss.

The second line of each test case contains exactly nn integers: a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤501 \leq a_i \leq 50) — the elements of the array aa.

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

第一行包含一个整数 tt(1≤t≤1031 \leq t \leq 10^3)—— 测试用例的数量。

随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤501 \leq n \leq 50)—— 数组 aa 和字符串 ss 的长度。

每个测试用例的第二行包含恰好 nn 个整数:a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤501 \leq a_i \leq 50)—— 数组 aa 的元素。

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

输出格式

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

对于每个测试用例,如果可以从数组 aa 得到字符串 ss,则输出 "YES";否则输出 "NO"。你可以以任意大小写形式输出每个字母。

输入输出样例

  • 输入#1

    7
    5
    2 3 2 4 1
    cacta
    1
    50
    a
    2
    11 22
    ab
    4
    1 2 2 1
    aaab
    5
    1 2 3 2 1
    aaaaa
    6
    1 10 2 9 3 8
    azzfdb
    7
    1 2 3 4 1 1 2
    abababb

    输出#1

    YES
    YES
    YES
    NO
    YES
    YES
    NO

说明/提示

The first test case corresponds to the sample described in the statement.

In the second test case we can choose the number 5050 and the letter a.

In the third test case we can choose the number 1111 and the letter a, after that a=[a,22]a = [a, 22]. Then we choose the number 2222 and the letter b and get a=[a,b]a = [a, b].

In the fifth test case we can change all numbers one by one to the letter a.

第一个测试用例对应题目描述中的样例。

在第二个测试用例中,我们可以选择数字 5050 和字母 a。

在第三个测试用例中,我们可以先选择数字 1111 和字母 a,之后得到 a=[a,22]a = [a, 22];然后选择数字 2222 和字母 b,最终得到 a=[a,b]a = [a, b]。

在第五个测试用例中,我们可以逐个将所有数字替换为字母 a。

输入解题思路,AI测评打分。不知道怎么写?

首页