You are given two strings ss and tt both of length nn and both consisting of lowercase Latin letters.

In one move, you can choose any length lenlen from 11 to nn and perform the following operation:

  • Choose any contiguous substring of the string ss of length lenlen and reverse it;
  • at the same time choose any contiguous substring of the string tt of length lenlen and reverse it as well.

Note that during one move you reverse exactly one substring of the string ss and exactly one substring of the string tt.

Also note that borders of substrings you reverse in ss and in tt can be different, the only restriction is that you reverse the substrings of equal length. For example, if len=3len=3 and n=5n=5, you can reverse s[1…3]s[1…3] and t[3…5]t[3…5], s[2…4]s[2…4] and t[2…4]t[2…4], but not s[1…3]s[1…3] and t[1…2]t[1…2].

Your task is to say if it is possible to make strings ss and tt equal after some (possibly, empty) sequence of moves.

You have to answer qq independent test cases.

Input

The first line of the input contains one integer qq (1≤q≤1041≤q≤104) — the number of test cases. Then qq test cases follow.

The first line of the test case contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the length of ss and tt.

The second line of the test case contains one string ss consisting of nn lowercase Latin letters.

The third line of the test case contains one string tt consisting of nn lowercase Latin letters.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑n≤2⋅105).

Output

For each test case, print the answer on it — "YES" (without quotes) if it is possible to make strings ss and tt equal after some (possibly, empty) sequence of moves and "NO" otherwise.

Example
input

Copy
4
4
abcd
abdc
5
ababa
baaba
4
asdf
asdg
4
abcd
badc
output

Copy
NO
YES
NO
YES

大概意思

现在给你两个字符串,你可以进行若干次操作。

每次操作需要在每个字符串都选择出长度为len的一个区间,两个区间位置不一定相同,然后将这个区间的字符都进行翻转。

问你进行若干次操作后,这俩字符串能变成一样的吗?

#include<bits/stdc++.h>
using namespace std;
int n;
string s1,s2,S1,S2;
//前两个满足, 如果两个字符串的逆的奇偶性相同,那么一定是YES
//在判断1和2之后,我们得到的一定是一个排列,问题就变成你可以翻转若干次,两个排列能否相同。
//我们考虑我们同时翻转相同长度的,我们排列的逆一定会发生奇偶性的变化,
//那么如果一开始奇偶性就不同,那么不管怎么翻转,都不会相同。
int Count(string s) {
int num=;
for(int i=; i<s.size(); i++) {
for(int j=; j<i; j++) {
if(s[j]>s[i])
num++;
}
}
return num;
}
void solve() {
cin>>n>>S1>>S2;
s1=S1;
s2=S2;
sort(s1.begin(),s1.end());
sort(s2.begin(),s2.end());
for(int i=; i<n; i++) {
if(s1[i]!=s2[i]) { //如果存在不同字符,那么一定不行
puts("NO");
return;
}
}
for(int i=; i<n; i++) {
if(s1[i]==s1[i-]) {//如果存在相同字符
puts("YES");
return;
}
if(s2[i]==s2[i-]) {
puts("YES");
return;
}
}
if(Count(S1)%==Count(S2)%) {
puts("YES");
} else {
puts("NO");
}
return;
}
int main() {
int t;
scanf("%d",&t);
while(t--)solve();
}

Codeforces Round #598 (Div. 3) F. Equalizing Two Strings的更多相关文章

  1. Codeforces Round #598 (Div. 3) F. Equalizing Two Strings 构造

    F. Equalizing Two Strings You are given two strings s and t both of length n and both consisting of ...

  2. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  3. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  4. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  5. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  6. Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划

    Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划 [Problem Description] 给你\( ...

  7. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  8. Codeforces Round #598 (Div. 3)

    传送门 A. Payment Without Change 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/4 21:19:19 */ #i ...

  9. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

随机推荐

  1. Python TCP与UDP的区别

    TCP:英文全拼(Transmission Control Protocol)简称传输控制协议,它是一种面向连接的.可靠的.基于字节流的传输层通信协议. TCP通信需要经过创建连接.数据传送.终止连接 ...

  2. [TJOI2009] 猜数字 - 中国剩余定理

    现有两组数字,每组k个,第一组中的数字分别为:a1,a2,...,ak表示,第二组中的数字分别用b1,b2,...,bk表示.其中第二组中的数字是两两互素的.求最小的非负整数n,满足对于任意的i,n ...

  3. [AtCoder Code Festival 2017 QualB D/At3575] 101 to 010 - dp

    [Atcoder Code Festival 2017 QualB/At3575] 101 to 010 有一个01序列,每次可以选出一个101,使其变成010,问最优策略下能操作几次? 考虑像 11 ...

  4. ORA-12638: 身份证明检索失败

    PLSQL 连接Oracle时提示 “ORA-12638: 身份证明检索失败” 错误, 但是开发IDE可以正常连接,DataGrid 可以正常连接,所以确定是本地设置问题. 网上搜了一下,说是因为Or ...

  5. WSO2 ESB XML定义语法(2)

    5.Proxy Service 配置 <proxy>元素用于定义Synapse代理服务. 通过基础Axis2引擎在指定的传输上创建和公开代理服务,根据标准的Axis2约定(即基于服务名称) ...

  6. PP: Robust Anomaly Detection for Multivariate Time Series through Stochastic Recurrent Neural Network

    PROBLEM: OmniAnomaly multivariate time series anomaly detection + unsupervised 主体思想: input: multivar ...

  7. 最长公共子串(LCS) lg SP1811

    后缀自动机的一大用处就是求最长公共子串了 这道题的话题意就是给你两个字符串,求最长公共子串 做法的话是先使用一个字符串建立SAM,然后让另一个串在上面进行匹配 匹配的策略是优先匹配当前节点的下一个字符 ...

  8. idea的插件库连不上网络

    如果你试遍了网上的方法都没有解决网络问题,建议换个网络,比如切换到电信网络.

  9. Web安全测试学习笔记 - 文件包含

    基础知识 文件包含指的是一个文件动态引用另一个文件,这是一种非常灵活的动态调用方式.有点类似Java引用jar包,但区别在于jar包引用后一般是固定不变的(一般不能动态改变所引用的jar包名称),而文 ...

  10. importing-cleaning-data-in-r-case-studies

    目录 importing-cleaning-data-in-r-case-studies 导入数据 查看数据结构 下面的一些都是查数据结构的 separate 拆分单元格 读取指定位置的数据 stri ...