欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2000C.Numeric String Template
Numeric String Template
Kristina has an array , called a template, consisting of integers. She also has strings, each consisting only of lowercase Latin letters. The strings are numbered from to . She wants to check which strings match the template.
A string is considered to match the template if all of the following conditions are simultaneously satisfied:
- The length of the string is equal to the number of elements in the array .
- The same numbers from correspond to the same symbols from . So, if , then for ().
- The same symbols from correspond to the same numbers from . So, if , then for ().
In other words, there must be a one-to-one correspondence between the characters of the string and the elements of the array.
For example, if = [], then the string "abfda" matches the template, while the string "afbfa" does not, since the character "f" corresponds to both numbers and .
Input
The first line of input contains a single integer () — the number of test cases.
The following descriptions are for the test cases.
The first line of each test case contains a single integer () — the number of elements in the array .
The second line of each test case contains exactly integers () — the elements of the array .
The third line of each test case contains a single integer () — the number of strings to check for template matching.
Following are strings, each containing a non-empty string (), consisting of lowercase Latin letters.
It is guaranteed that the sum of across all test cases does not exceed , and that the sum of the lengths of all strings does not exceed .
Output
For each test case, output lines. On the -th line () output:
- "
YES", if the string with index matches the template; - "
NO" otherwise.
You may output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).
Note
The first test case is explained in the problem statement.
Samples
3
5
3 5 2 1 3
2
abfda
afbfa
2
1 2
3
ab
abc
aa
4
5 -3 5 -3
4
aaaa
bcbc
aba
cbcb
YES
NO
YES
NO
NO
NO
YES
NO
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |