CF1898E.Sofia and Strings
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Sofia has a string s of length n, consisting only of lowercase English letters. She can perform operations of the following types with this string.
- Select an index 1≤i≤∣s∣ and remove the character si from the string.
- Select a pair of indices (l,r) (1≤l≤r≤∣s∣) and sort the substring slsl+1…sr in alphabetical order.
Here, ∣s∣ denotes the current length of s. In particular, ∣s∣=n before the first operation. For example, if s=sofia, then performing the operation of the first type with i=4 results in s becoming sofa, and performing the operation of the second type with (l,r)=(2,4) after that results in s becoming safo.
Sofia wants to obtain the string t of length m after performing zero or more operations on string s as described above. Please determine whether it is possible or not.
索菲亚有一个长度为 n 的字符串 s,其中仅包含小写英文字母。她可以对这个字符串执行以下两类操作:
- 选择一个下标 1≤i≤∣s∣,从字符串中删除字符 si;
- 选择一对下标 (l,r)(满足 1≤l≤r≤∣s∣),将子串 slsl+1…sr 按字母顺序升序排序。
此处,∣s∣ 表示字符串 s 的当前长度;特别地,在第一次操作前有 ∣s∣=n。例如,若 s=sofia,则执行第一类操作并取 i=4 后,s 变为 sofa;再在此基础上执行第二类操作并取 (l,r)=(2,4),则 s 变为 safo。
索菲亚希望通过对字符串 s 执行零次或多次上述操作,最终得到长度为 m 的字符串 t。请判断该目标是否可达。
输入格式
The first line contains one integer t (1≤t≤10000) — the number of test cases.
The first line of each test case contains two integers n, m (1≤m≤n≤2⋅105) — the lengths of string s and t, respectively.
The second line of each test case contains the string s of length n, consisting only of lowercase English letters.
The third line of each test case contains the string t of length m, consisting only of lowercase English letters.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤10000)—— 表示测试用例的数量。
每个测试用例的第一行包含两个整数 n、m(1≤m≤n≤2⋅105)—— 分别表示字符串 s 和 t 的长度。
每个测试用例的第二行包含一个长度为 n 的字符串 s,仅由小写英文字母组成。
每个测试用例的第三行包含一个长度为 m 的字符串 t,仅由小写英文字母组成。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output "YES" if Sofia can obtain the string t from s using the operations above. Otherwise, output "NO".
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
对于每个测试用例,如果索菲亚能通过上述操作从字符串 s 得到字符串 t,则输出 "YES";否则输出 "NO"。
你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答。
输入输出样例
输入#1
8 5 5 sofia afios 3 2 cba bc 5 1 sofia e 15 7 anavolimilovana aamanan 26 4 abcdefghijklmnopqrstuvwxyz nope 26 4 zyxwvutsrqponmlkjihgfedcba nope 7 3 apricot cat 3 3 cba acb
输出#1
YES YES NO YES NO YES NO YES
说明/提示
In the first test case, Sofia can perform the following operation:
- operation of the second type with l=1 and r=5: string s becomes afios after it.
In the second test case, Sofia can perform the following operations:
- operation of the second type with l=1 and r=2: string s becomes bca after it;
- operation of the first type with i=3: string s becomes bc after it.
In the third test case, it can be shown that it is impossible to obtain t from s using the provided operations.
在第一个测试用例中,索菲亚可以执行以下操作:
- 执行第二种类型的操作,其中 l=1 且 r=5:字符串 s 将变为 afios。
在第二个测试用例中,索菲亚可以执行以下操作:
- 执行第二种类型的操作,其中 l=1 且 r=2:字符串 s 将变为 bca;
- 执行第一种类型的操作,其中 i=3:字符串 s 将变为 bc。
在第三个测试用例中,可以证明:无法通过给定的操作将 s 变为 t。
输入解题思路,AI测评打分。不知道怎么写?