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. H3C DRNI学习

    DRNI:Distributed Resilient Network Interconnect,分布式弹性网络互连.DR:分布式聚合接口IPP:内部控制链路端口IPL:内部控制链路DRCP报文:分布式 ...

  2. php laravel请求处理管道(装饰者模式)

    laravel的中间件使用了装饰者模式.比如,验证维护模式,cookie加密,开启会话等等.这些处理有些在响应前,有些在响应之后,使用装饰者模式动态减少或增加功能,使得框架可扩展性大大增强. 接下来简 ...

  3. 用python读写和处理csv文件

    import requestsfrom bs4 import BeautifulSoupimport csv date = open('test.csv', 'w')writer = csv.writ ...

  4. 3、Hibernate的多表关联

    一.数据库中的表关系: 一对一关系 一个人对应一张身份证,一张身份证对应一个人,一对一关系是最好理解的一种关系,在数据库建表的时候可以将人表的主键放置与身份证表里面,也可以将身份证表的主键放置于人表里 ...

  5. 登录注册案例(Servlet+JSP+Maven)

    项目案例模板之登录注册的实现 案例演示 案例代码 设计表 pom.xml  <dependencies>  <dependency>    <groupId>jun ...

  6. js获取当前日期一年的第几周

    获取当前日期一年中的第几周 function theWeek() { ; now = new Date(); years = now.getYear() ) years += ); days[] = ...

  7. ES6数组及对象遍历的新增方法 entries(),keys() 和 values()

    ES6 提供三个新的方法——entries(),keys()和values()——用于遍历数组.它们都返回一个遍历器对象(详见<Iterator>一章),可以用for...of循环进行遍历 ...

  8. 【转载】编程语言排行榜2019年7月 TIOBE编程语言排行榜2019年最新版

    TIOBE在前段时间公布了编程语言排行榜2019年7月的数据,编程语言7月的排名有了新的变化,Python继教占领第三名,Java还是稳居第一,C++本月又降了0.91%.下面一起来看看2019年7月 ...

  9. Linux:路径的概念及路径的切换

    路径分为绝对路径和相对路径 绝对路径:从/根开头的路径为绝对路径 相对路径:以当前目录为开头的为相对路径 根目录:/ 家目录:普通用户的家目录在/home下,root用户的家目录是/root 切换目录 ...

  10. postman---postman简单介绍

    有小伙伴们想要了解postman,今天它来了,不要问它到底有多强大,自古免费好用即是王道,它不仅仅是开发接口强大的调试工具,还是测试接口的居家必备,它不仅仅可以把需要调用的接口保存下来方便调用,还可以 ...