CF1730D.Prefixes and Suffixes

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have two strings s1s_1 and s2s_2 of length nn, consisting of lowercase English letters. You can perform the following operation any (possibly zero) number of times:

  • Choose a positive integer 1≤k≤n1 \leq k \leq n.
  • Swap the prefix of the string s1s_1 and the suffix of the string s2s_2 of length kk.

Is it possible to make these two strings equal by doing described operations?

你有两个长度为 nn 的字符串 s1s_1 和 s2s_2,均由小写英文字母组成。你可以执行以下操作任意次(可以为零次):

  • 选择一个正整数 1≤k≤n1 \leq k \leq n;
  • 交换字符串 s1s_1 的长度为 kk 的前缀与字符串 s2s_2 的长度为 kk 的后缀。

能否通过执行上述操作使得这两个字符串相等?

输入格式

The first line contains a single integer tt (1≤t≤1041 \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 nn (1≤n≤1051 \le n \le 10^5) — the length of the strings s1s_1 and s2s_2.

The second line contains the string s1s_1 of length nn, consisting of lowercase English letters.

The third line contains the string s2s_2 of length nn, consisting of lowercase English letters.

It is guaranteed that the sum of nn for all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。随后是各测试用例。

每个测试用例由三行组成。

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 表示字符串 s1s_1 和 s2s_2 的长度。

第二行包含一个长度为 nn 的字符串 s1s_1,由小写英文字母组成。

第三行包含一个长度为 nn 的字符串 s2s_2,由小写英文字母组成。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print "YES" if it is possible to make the strings equal, and "NO" otherwise.

对于每个测试用例,如果可以使两个字符串相等,则输出 “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

说明/提示

In the first test case:

  • Initially s1=cbcs_1 = \mathtt{cbc}, s2=abas_2 = \mathtt{aba}.
  • Operation with k=1k = 1, after the operation s1=abcs_1 = \mathtt{abc}, s2=abcs_2 = \mathtt{abc}.

In the second test case:

  • Initially s1=abcaas_1 = \mathtt{abcaa}, s2=cbabbs_2 = \mathtt{cbabb}.
  • Operation with k=2k = 2, after the operation s1=bbcaas_1 = \mathtt{bbcaa}, s2=cbaabs_2 = \mathtt{cbaab}.
  • Operation with k=3k = 3, after the operation s1=aabaas_1 = \mathtt{aabaa}, s2=cbbbcs_2 = \mathtt{cbbbc}.
  • Operation with k=1k = 1, after the operation s1=cabaas_1 = \mathtt{cabaa}, s2=cbbbas_2 = \mathtt{cbbba}.
  • Operation with k=2k = 2, after the operation s1=babaas_1 = \mathtt{babaa}, s2=cbbcas_2 = \mathtt{cbbca}.
  • Operation with k=1k = 1, after the operation s1=aabaas_1 = \mathtt{aabaa}, s2=cbbcbs_2 = \mathtt{cbbcb}.
  • Operation with k=2k = 2, after the operation s1=cbbaas_1 = \mathtt{cbbaa}, s2=cbbaas_2 = \mathtt{cbbaa}.

In the third test case, it's impossible to make strings equal.

在第一个测试用例中:

  • 初始时 s1=cbcs_1 = \mathtt{cbc},s2=abas_2 = \mathtt{aba}。
  • 执行 k=1k = 1 的操作后,s1=abcs_1 = \mathtt{abc},s2=abcs_2 = \mathtt{abc}。

在第二个测试用例中:

  • 初始时 s1=abcaas_1 = \mathtt{abcaa},s2=cbabbs_2 = \mathtt{cbabb}。
  • 执行 k=2k = 2 的操作后,s1=bbcaas_1 = \mathtt{bbcaa},s2=cbaabs_2 = \mathtt{cbaab}。
  • 执行 k=3k = 3 的操作后,s1=aabaas_1 = \mathtt{aabaa},s2=cbbbcs_2 = \mathtt{cbbbc}。
  • 执行 k=1k = 1 的操作后,s1=cabaas_1 = \mathtt{cabaa},s2=cbbbas_2 = \mathtt{cbbba}。
  • 执行 k=2k = 2 的操作后,s1=babaas_1 = \mathtt{babaa},s2=cbbcas_2 = \mathtt{cbbca}。
  • 执行 k=1k = 1 的操作后,s1=aabaas_1 = \mathtt{aabaa},s2=cbbcbs_2 = \mathtt{cbbcb}。
  • 执行 k=2k = 2 的操作后,s1=cbbaas_1 = \mathtt{cbbaa},s2=cbbaas_2 = \mathtt{cbbaa}。

在第三个测试用例中,无法使两个字符串相等。

输入解题思路,AI测评打分。不知道怎么写?

首页