309754: CF1730D. Prefixes and Suffixes
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Prefixes and Suffixes
题意翻译
有两个字符串$s$,$t$,有一种操作,代表每次可以交换长度为k的s的前缀和t的后缀,可以操作任意次,判断操作是否使得$s=t$。题目描述
You have two strings $ s_1 $ and $ s_2 $ of length $ n $ , consisting of lowercase English letters. You can perform the following operation any (possibly zero) number of times: - Choose a positive integer $ 1 \leq k \leq n $ . - Swap the prefix of the string $ s_1 $ and the suffix of the string $ s_2 $ of length $ k $ . Is it possible to make these two strings equal by doing described operations?输入输出格式
输入格式
The first line contains a single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases. Then the test cases follow. Each test case consists of three lines. The first line contains a single integer $ n $ ( $ 1 \le n \le 10^5 $ ) — the length of the strings $ s_1 $ and $ s_2 $ . The second line contains the string $ s_1 $ of length $ n $ , consisting of lowercase English letters. The third line contains the string $ s_2 $ of length $ n $ , consisting of lowercase English letters. It is guaranteed that the sum of $ n $ for all test cases does not exceed $ 2 \cdot 10^5 $ .
输出格式
For each test case, print "YES" if it is possible to make the strings equal, and "NO" otherwise.
输入输出样例
输入样例 #1
7
3
cbc
aba
5
abcaa
cbabb
5
abcaa
cbabz
1
a
a
1
a
b
6
abadaa
adaaba
8
abcabdaa
adabcaba
输出样例 #1
YES
YES
NO
YES
NO
NO
YES
说明
In the first test case: - Initially $ s_1 = \mathtt{cbc} $ , $ s_2 = \mathtt{aba} $ . - Operation with $ k = 1 $ , after the operation $ s_1 = \mathtt{abc} $ , $ s_2 = \mathtt{abc} $ . In the second test case: - Initially $ s_1 = \mathtt{abcaa} $ , $ s_2 = \mathtt{cbabb} $ . - Operation with $ k = 2 $ , after the operation $ s_1 = \mathtt{bbcaa} $ , $ s_2 = \mathtt{cbaab} $ . - Operation with $ k = 3 $ , after the operation $ s_1 = \mathtt{aabaa} $ , $ s_2 = \mathtt{cbbbc} $ . - Operation with $ k = 1 $ , after the operation $ s_1 = \mathtt{cabaa} $ , $ s_2 = \mathtt{cbbba} $ . - Operation with $ k = 2 $ , after the operation $ s_1 = \mathtt{babaa} $ , $ s_2 = \mathtt{cbbca} $ . - Operation with $ k = 1 $ , after the operation $ s_1 = \mathtt{aabaa} $ , $ s_2 = \mathtt{cbbcb} $ . - Operation with $ k = 2 $ , after the operation $ s_1 = \mathtt{cbbaa} $ , $ s_2 = \mathtt{cbbaa} $ . In the third test case, it's impossible to make strings equal.Input
题意翻译
有两个字符串$s$,$t$,有一种操作,代表每次可以交换长度为k的s的前缀和t的后缀,可以操作任意次,判断操作是否使得$s=t$。Output
**题意翻译**
有两个字符串 \( s \) 和 \( t \),可以通过交换 \( s \) 的前缀和 \( t \) 的后缀(长度为 \( k \))来进行操作,可以执行任意次。判断是否可以通过这些操作使得 \( s = t \)。
**题目描述**
你有两个长度为 \( n \) 的字符串 \( s_1 \) 和 \( s_2 \),由小写英文字母组成。你可以执行以下操作任意(可能为零)次数:
- 选择一个正整数 \( 1 \leq k \leq n \)。
- 交换字符串 \( s_1 \) 的前缀和字符串 \( s_2 \) 的后缀,长度均为 \( k \)。
通过执行上述操作,是否可以使这两个字符串相等?
**输入输出格式**
**输入格式**
第一行包含一个整数 \( t \)(\( 1 \le t \le 10^4 \))——测试用例的数量。然后是测试用例。
每个测试用例由三行组成。
第一行包含一个整数 \( n \)(\( 1 \le n \le 10^5 \))——字符串 \( s_1 \) 和 \( s_2 \) 的长度。
第二行包含一个长度为 \( n \) 的字符串 \( s_1 \),由小写英文字母组成。
第三行包含一个长度为 \( n \) 的字符串 \( s_2 \),由小写英文字母组成。
保证所有测试用例的 \( n \) 之和不超过 \( 2 \cdot 10^5 \)。
**输出格式**
对于每个测试用例,如果可以通过操作使字符串相等,则打印 "YES",否则打印 "NO"。
**输入输出样例**
**输入样例 #1**
```
7
3
cbc
aba
5
abcaa
cbabb
5
abcaa
cbabz
1
a
a
1
a
b
6
abadaa
adaaba
8
abcabdaa
adabcaba
```
**输出样例 #1**
```
YES
YES
NO
YES
NO
NO
YES
```
**说明**
在第一个测试用例中:
- 初始时 \( s_1 = \texttt{cbc} \),\( s_2 = \texttt{aba} \)。
- 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{abc} \),\( s_2 = \texttt{abc} \)。
第二个测试用例:
- 初始时 \( s_1 = \texttt{abcaa} \),\( s_2 = \texttt{cbabb} \)。
- 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{bbcaa} \),\( s_2 = \texttt{cbaab} \)。
- 使用 \( k = 3 \) 进行操作,操作后 \( s_1 = \texttt{aabaa} \),\( s_2 = \texttt{cbbbc} \)。
- 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{cabaa} \),\( s_2 = \texttt{cbbba} \)。
- 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{babaa} \),\( s_2 = \texttt{cbbca} \)。
- 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{aabaa} \),\( s_2 = \texttt{cbbcb} \)。
- 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{cbbaa} \),\( s_2 = \texttt{cbbaa} \)。
在第三个测试用例中,无法使字符串相等。**题意翻译** 有两个字符串 \( s \) 和 \( t \),可以通过交换 \( s \) 的前缀和 \( t \) 的后缀(长度为 \( k \))来进行操作,可以执行任意次。判断是否可以通过这些操作使得 \( s = t \)。 **题目描述** 你有两个长度为 \( n \) 的字符串 \( s_1 \) 和 \( s_2 \),由小写英文字母组成。你可以执行以下操作任意(可能为零)次数: - 选择一个正整数 \( 1 \leq k \leq n \)。 - 交换字符串 \( s_1 \) 的前缀和字符串 \( s_2 \) 的后缀,长度均为 \( k \)。 通过执行上述操作,是否可以使这两个字符串相等? **输入输出格式** **输入格式** 第一行包含一个整数 \( t \)(\( 1 \le t \le 10^4 \))——测试用例的数量。然后是测试用例。 每个测试用例由三行组成。 第一行包含一个整数 \( n \)(\( 1 \le n \le 10^5 \))——字符串 \( s_1 \) 和 \( s_2 \) 的长度。 第二行包含一个长度为 \( n \) 的字符串 \( s_1 \),由小写英文字母组成。 第三行包含一个长度为 \( n \) 的字符串 \( s_2 \),由小写英文字母组成。 保证所有测试用例的 \( n \) 之和不超过 \( 2 \cdot 10^5 \)。 **输出格式** 对于每个测试用例,如果可以通过操作使字符串相等,则打印 "YES",否则打印 "NO"。 **输入输出样例** **输入样例 #1** ``` 7 3 cbc aba 5 abcaa cbabb 5 abcaa cbabz 1 a a 1 a b 6 abadaa adaaba 8 abcabdaa adabcaba ``` **输出样例 #1** ``` YES YES NO YES NO NO YES ``` **说明** 在第一个测试用例中: - 初始时 \( s_1 = \texttt{cbc} \),\( s_2 = \texttt{aba} \)。 - 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{abc} \),\( s_2 = \texttt{abc} \)。 第二个测试用例: - 初始时 \( s_1 = \texttt{abcaa} \),\( s_2 = \texttt{cbabb} \)。 - 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{bbcaa} \),\( s_2 = \texttt{cbaab} \)。 - 使用 \( k = 3 \) 进行操作,操作后 \( s_1 = \texttt{aabaa} \),\( s_2 = \texttt{cbbbc} \)。 - 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{cabaa} \),\( s_2 = \texttt{cbbba} \)。 - 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{babaa} \),\( s_2 = \texttt{cbbca} \)。 - 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{aabaa} \),\( s_2 = \texttt{cbbcb} \)。 - 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{cbbaa} \),\( s_2 = \texttt{cbbaa} \)。 在第三个测试用例中,无法使字符串相等。
有两个字符串 \( s \) 和 \( t \),可以通过交换 \( s \) 的前缀和 \( t \) 的后缀(长度为 \( k \))来进行操作,可以执行任意次。判断是否可以通过这些操作使得 \( s = t \)。
**题目描述**
你有两个长度为 \( n \) 的字符串 \( s_1 \) 和 \( s_2 \),由小写英文字母组成。你可以执行以下操作任意(可能为零)次数:
- 选择一个正整数 \( 1 \leq k \leq n \)。
- 交换字符串 \( s_1 \) 的前缀和字符串 \( s_2 \) 的后缀,长度均为 \( k \)。
通过执行上述操作,是否可以使这两个字符串相等?
**输入输出格式**
**输入格式**
第一行包含一个整数 \( t \)(\( 1 \le t \le 10^4 \))——测试用例的数量。然后是测试用例。
每个测试用例由三行组成。
第一行包含一个整数 \( n \)(\( 1 \le n \le 10^5 \))——字符串 \( s_1 \) 和 \( s_2 \) 的长度。
第二行包含一个长度为 \( n \) 的字符串 \( s_1 \),由小写英文字母组成。
第三行包含一个长度为 \( n \) 的字符串 \( s_2 \),由小写英文字母组成。
保证所有测试用例的 \( n \) 之和不超过 \( 2 \cdot 10^5 \)。
**输出格式**
对于每个测试用例,如果可以通过操作使字符串相等,则打印 "YES",否则打印 "NO"。
**输入输出样例**
**输入样例 #1**
```
7
3
cbc
aba
5
abcaa
cbabb
5
abcaa
cbabz
1
a
a
1
a
b
6
abadaa
adaaba
8
abcabdaa
adabcaba
```
**输出样例 #1**
```
YES
YES
NO
YES
NO
NO
YES
```
**说明**
在第一个测试用例中:
- 初始时 \( s_1 = \texttt{cbc} \),\( s_2 = \texttt{aba} \)。
- 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{abc} \),\( s_2 = \texttt{abc} \)。
第二个测试用例:
- 初始时 \( s_1 = \texttt{abcaa} \),\( s_2 = \texttt{cbabb} \)。
- 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{bbcaa} \),\( s_2 = \texttt{cbaab} \)。
- 使用 \( k = 3 \) 进行操作,操作后 \( s_1 = \texttt{aabaa} \),\( s_2 = \texttt{cbbbc} \)。
- 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{cabaa} \),\( s_2 = \texttt{cbbba} \)。
- 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{babaa} \),\( s_2 = \texttt{cbbca} \)。
- 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{aabaa} \),\( s_2 = \texttt{cbbcb} \)。
- 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{cbbaa} \),\( s_2 = \texttt{cbbaa} \)。
在第三个测试用例中,无法使字符串相等。**题意翻译** 有两个字符串 \( s \) 和 \( t \),可以通过交换 \( s \) 的前缀和 \( t \) 的后缀(长度为 \( k \))来进行操作,可以执行任意次。判断是否可以通过这些操作使得 \( s = t \)。 **题目描述** 你有两个长度为 \( n \) 的字符串 \( s_1 \) 和 \( s_2 \),由小写英文字母组成。你可以执行以下操作任意(可能为零)次数: - 选择一个正整数 \( 1 \leq k \leq n \)。 - 交换字符串 \( s_1 \) 的前缀和字符串 \( s_2 \) 的后缀,长度均为 \( k \)。 通过执行上述操作,是否可以使这两个字符串相等? **输入输出格式** **输入格式** 第一行包含一个整数 \( t \)(\( 1 \le t \le 10^4 \))——测试用例的数量。然后是测试用例。 每个测试用例由三行组成。 第一行包含一个整数 \( n \)(\( 1 \le n \le 10^5 \))——字符串 \( s_1 \) 和 \( s_2 \) 的长度。 第二行包含一个长度为 \( n \) 的字符串 \( s_1 \),由小写英文字母组成。 第三行包含一个长度为 \( n \) 的字符串 \( s_2 \),由小写英文字母组成。 保证所有测试用例的 \( n \) 之和不超过 \( 2 \cdot 10^5 \)。 **输出格式** 对于每个测试用例,如果可以通过操作使字符串相等,则打印 "YES",否则打印 "NO"。 **输入输出样例** **输入样例 #1** ``` 7 3 cbc aba 5 abcaa cbabb 5 abcaa cbabz 1 a a 1 a b 6 abadaa adaaba 8 abcabdaa adabcaba ``` **输出样例 #1** ``` YES YES NO YES NO NO YES ``` **说明** 在第一个测试用例中: - 初始时 \( s_1 = \texttt{cbc} \),\( s_2 = \texttt{aba} \)。 - 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{abc} \),\( s_2 = \texttt{abc} \)。 第二个测试用例: - 初始时 \( s_1 = \texttt{abcaa} \),\( s_2 = \texttt{cbabb} \)。 - 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{bbcaa} \),\( s_2 = \texttt{cbaab} \)。 - 使用 \( k = 3 \) 进行操作,操作后 \( s_1 = \texttt{aabaa} \),\( s_2 = \texttt{cbbbc} \)。 - 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{cabaa} \),\( s_2 = \texttt{cbbba} \)。 - 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{babaa} \),\( s_2 = \texttt{cbbca} \)。 - 使用 \( k = 1 \) 进行操作,操作后 \( s_1 = \texttt{aabaa} \),\( s_2 = \texttt{cbbcb} \)。 - 使用 \( k = 2 \) 进行操作,操作后 \( s_1 = \texttt{cbbaa} \),\( s_2 = \texttt{cbbaa} \)。 在第三个测试用例中,无法使字符串相等。