time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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:

They are equal.

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:

a1 is equivalent to b1, and a2 is equivalent to b2

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”.

【题目链接】:http://codeforces.com/contest/560/problem/D

【题解】



写个递归就过了;

中间如果遇到字符串的长度为奇数则直接返回false;

感觉这样能剪掉挺多情况的。就交了一发;结果真的过了;

事后看到好多人都在第91个点T了。我看了一下500ms左右。不知道为什么;

还是应该对自己自信点吧!



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); string s1,s2; bool f(string a,string b)
{
if (a==b) return true;
int len1 = a.size(),len2 = b.size();
if (len1&1 || len2 &1) return false;
if (len1==1)
return false;
string ta1 = a.substr(0,len1/2),ta2 = a.substr(len1/2,len1/2);
string tb1 = b.substr(0,len2/2),tb2 = b.substr(len2/2,len2/2);
return (f(ta1,tb2)&&f(ta2,tb1))||(f(ta1,tb1)&&f(ta2,tb2));
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> s1;cin >> s2;
if (f(s1,s2))
puts("YES");
else
puts("NO");
return 0;
}

【24.34%】【codeforces 560D】Equivalent Strings的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. 【34.57%】【codeforces 557D】Vitaly and Cycle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【24.17%】【codeforces 721D】Maxim and Array

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【34.88%】【codeforces 569C】Primes or Palindromes?

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【22.73%】【codeforces 606D】Lazy Student

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  8. 【codeforces 793D】Presents in Bankopolis

    [题目链接]:http://codeforces.com/contest/793/problem/D [题意] 给你n个点, 这n个点 从左到右1..n依序排; 然后给你m条有向边; 然后让你从中选出 ...

  9. 【codeforces 799D】Field expansion

    [题目链接]:http://codeforces.com/contest/799/problem/D [题意] 给你长方形的两条边h,w; 你每次可以从n个数字中选出一个数字x; 然后把h或w乘上x; ...

随机推荐

  1. 使用gnu automake编译helloworld

    使用gnu automake编译helloworld 按照许多介绍automake基本步骤的教程中的说法,我在尝试使用automake编译helloworld示例程序的时候,仍然遇到了几个小坑,所幸后 ...

  2. 内存泄漏与指针悬挂&野指针介绍

    内存泄漏概念:内存泄漏时指动态申请的内存空间没有正常释放,但是也不能继续使用的情况. 例如: char *ch1; ch1 = new char('A'); char = *ch2 = new cha ...

  3. BZOJ 1009 GT考试 (AC自动机 + 矩阵乘法加速dp)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1009 题意: 准考证号为\(n\)位数\(X_1X_2....X_n(0<=X_ ...

  4. mysql 批量删除数据

    批量删除2000w数据 使用delete from table太慢 //DELIMITER DROP PROCEDURE if EXISTS deleteManyTable; create PROCE ...

  5. 轻松学习Linux之Shell的常用过滤器

    下载高清视频: http://down.51cto.com/data/157818    大小3:MB      时长: 7分钟 更多内容见: Linux爱好者的圣诞大餐-轻松学习Linux系列多媒体 ...

  6. beego的orm ,用的数据库sqlite3

    测试 beego的orm ,用的数据库sqlite3 1 package main import ( "fmt" "github.com/astaxie/beego/or ...

  7. JavaScript--数据结构与算法之排序

    排序总结————常见的排序 常见的9中排序(冒泡,选择,插入(二分插入,希尔),归并,快速,堆,计数,基数,桶排序)可分为两类 比较排序:冒泡,选择,插入(二分插入,希尔),归并,堆,快速 非比较排序 ...

  8. 一起talk C栗子吧(第九回:C语言实例--最大公约数)

    各位看官们,大家好.从今天開始,我们讲大型章回体科技小说 :C栗子,也就是C语言实例.闲话休提, 言归正转.让我们一起talk C栗子吧! 看官们.上一回中咱们说的是素数的样例.这一回咱们说的样例是: ...

  9. 好玩的 emoji

    emoji 就是表情符号,来自日语词汇"絵文字"(假名为"えもじ",读音即emoji).emoji 表情符号大全,都在这里(手机/电脑都可以复制):www.fu ...

  10. 无法显式调用运算符或访问器 错误处理方法 DLL study

    无法显式调用运算符或访问器 错误处理方法 转 无法显式调用运算符或访问器 错误处理方法 反汇编一个dll类库,导出的项目会报出很多bug,其中主要的就是“无法显式调用运算符或访问器”这个错误,看了一下 ...