Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:

  1. They are equal.
  2. If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2, then one of the following is correct:
    1. a1 is equivalent to b1, and a2 is equivalent to b2
    2. a1 is equivalent to b2, and a2 is equivalent to b1

As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.

Gerald has already completed this home task. Now it's your turn!

Input

The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200 000 and consists of lowercase English letters. The strings have the same length.

Output

Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.

Examples

Input
aaba
abaa
Output
YES
Input
aabb
abab
Output
NO

Note

In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".

In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".

OJ-ID:
CodeForce-560D
author:
Caution_X

date of submission:
20191026

tags:
dfs

description modelling:
判断两个字符串是否“相等”。
相等:
(1)a=b
(2)a分成长度相等的两份a1,a2,b分成长度相等的两份b1,b2,并满足a1=b1&&a2=b2或者a1=b2&&a2=b1(语法上满足(string)a=(string)a1+(string)a2)。

major steps to solve it:
(1)裸dfs无剪枝

AC code:

#include<bits/stdc++.h>
using namespace std;
bool dfs(string a,string b)
{
int lena=a.length(),lenb=b.length();
string ta1=a.substr(,lena/),ta2=a.substr(lena/,lena/);
string tb1=b.substr(,lenb/),tb2=b.substr(lenb/,lenb/);
if(a==b) return true;
if(a.length()%!=) return false;
if(dfs(ta1,tb2)&&dfs(ta2,tb1)) return true;
if(dfs(ta1,tb1)&&dfs(ta2,tb2)) return true;
return false;
}
int main()
{
string a,b;
cin>>a>>b;
if(a==b) puts("YES");
else if(a.length()!=b.length()) puts("NO");
else if(dfs(a,b)) puts("YES");
else puts("NO");
return ;
}

CodeForces - 560D Equivalent Strings的更多相关文章

  1. Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)

    D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. Codeforces 559B - Equivalent Strings

    559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...

  3. Codeforces - 559B - Equivalent Strings - 分治

    http://codeforces.com/problemset/problem/559/B 这个题目,分治就好了,每次偶数层可以多一种判断方式,判断它的时间就是logn的(吧),注意奇数层并不是直接 ...

  4. codeforces 559b//Equivalent Strings// Codeforces Round #313(Div. 1)

    题意:定义了字符串的相等,问两串是否相等. 卡了时间,空间,不能新建字符串,否则会卡. #pragma comment(linker,"/STACK:1024000000,102400000 ...

  5. Codeforces 559B Equivalent Strings 等价串

    题意:给定两个等长串a,b.推断是否等价.等价的含义为:若长度为奇数,则必须是同样串.若长度是偶数,则将两串都均分成长度为原串一半的两个子串al,ar和bl,br,当中al和bl等价且ar和br等价, ...

  6. Codeforces Round #313 (Div. 1) B. Equivalent Strings

    Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...

  7. Codeforces Round #313 (Div. 2) D. Equivalent Strings

    D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...

  8. Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力

    B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559 ...

  9. Codeforces Round #313 D. Equivalent Strings(DFS)

    D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. centos 8 docker-ce 安装

    https://www.techrepublic.com/article/a-better-way-to-install-docker-on-centos-8/ https://linuxconfig ...

  2. Web前端——Html常用标签及属性

    html 常用的标题等标签就不记录了,只记录一下比较少见的标签以及属性 表格 table td 单元格 tr 表的行 th 表头 td或th可以下面的两个属性达到跨行或跨列 表格跨行 rowspan ...

  3. 用python执行Linux命令

    例1:在python中包装ls命令 #!/usr/bin/env python #python wapper for the ls command import subprocess subproce ...

  4. python web框架Django——ORM

    ORM简介 MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库 ORM是“对象-关系-映射”的简称 ...

  5. jsp表单数据添加到数据库

    先由表单提交数据到某验证页面:checkregister.jsp<form method="POST"name="form1" action=" ...

  6. ABP进阶教程11 - 小结

    点这里进入ABP进阶教程目录 效果预览 至此,ABP进阶教程的查询/分页/排序/导出/打印示例已完成,效果如下 登录 首页 办公室信息 院系信息 课程信息 教职员信息 学生信息 新增 修改 删除 查询 ...

  7. python中字符串

    字符串:可用单引号 双引号 三引号 来表示 可用来定义国籍,姓名,家庭住址等选项:#.join 把可迭代的对象转化成字符串 (字符串,列表,元组,字典等),列表 元组 合并为字符串,字典合并的是key ...

  8. nRF24L01+如何检测信道被占用-RSSI寄存器实战分享

    检测信道占用的需求场景 在使用nRF24L01模块做一对多或多对一的组网通信中,大家都会担心一个问题就是在发送的时候,希望不要有其他的模块也进行发送,因为这样就会使无线信号发生碰撞,信道被堵塞,造成通 ...

  9. css伪类实现行号自动填充

    css伪类实现行号自动填充 大多数时候我们需要行号自动填充的时候我们可以 大多数时候是插入元素, 在元素里用js填入行号,或者用 ol > li 实现行号填充, 对于上面的方式,都不太灵活,而且 ...

  10. Python—函数进阶篇

    lambda表达式(匿名函数表达式) 作用:创建一个匿名函数对象.同def类似,但不提供函数名. 语法:lambda [形参1,形参2,...] : 表达式 语法说明 lambda 只是一个表达式,它 ...