A15377 | Number Replacement
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
An integer array $a_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 $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?
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?
输入格式
The first line contains a single integer $t$ $(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 $n$ ( $1 \leq n \leq 50$ ) — the length of the array $a$ and the string $s$ .
The second line of each test case contains exactly $n$ integers: $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 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.
Then the description of the test cases follows.
The first line of each test case contains a single integer $n$ ( $1 \leq n \leq 50$ ) — the length of the array $a$ and the string $s$ .
The second line of each test case contains exactly $n$ integers: $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 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.
输出格式
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.
输入输出样例
输入 #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 $50$ and the letter a.
In the third test case we can choose the number $11$ and the letter a, after that $a = [a, 22]$ . Then we choose the number $22$ and the letter b and get $a = [a, b]$ .
In the fifth test case we can change all numbers one by one to the letter a.
In the second test case we can choose the number $50$ and the letter a.
In the third test case we can choose the number $11$ and the letter a, after that $a = [a, 22]$ . Then we choose the number $22$ and the letter b and get $a = [a, b]$ .
In the fifth test case we can change all numbers one by one to the letter a.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted