[Solution] Number Replacement Codeforces Solution
An integer array 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 from the array , and any letter of the English alphabet .
- Replace all occurrences of number with the letter .
For example, if we initially had an array , then we could transform it the following way:
- Choose the number and the letter c. After that .
- Choose the number and the letter a. After that .
- Choose the number and the letter t. After that .
- Choose the number and the letter a. After that .
After the transformation all letters are united into a string, in our example we get the string "cacta".
Having the array and the string determine if the string could be got from the array after the described transformation?
The first line contains a single integer ) — the number of test cases.
Then the description of the test cases follows.
The first line of each test case contains a single integer () — the length of the array and the string .
The second line of each test case contains exactly integers: () — the elements of the array .
The third line of each test case contains a string of length , consisting of lowercase English letters.
For each test case, output "YES", if we can get the string from the array , and "NO" otherwise. You can output each letter in any case.
The first test case corresponds to the sample described in the statement.
In the second test case we can choose the number and the letter a.
In the third test case we can choose the number and the letter a, after that . Then we choose the number and the letter b and get .
In the fifth test case we can change all numbers one by one to the letter a.
No comments:
Post a Comment