D. Equivalent Strings
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of
equal length are calledequivalent 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.

Sample test(s)
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".

    #include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; char a[200010],b[200010]; int DFS(char *a,char *b,int l)
{
if(strncmp(a,b,l) == 0)
{
return 1;
}
if(l%2)
{
return 0;
}
int p = l / 2;
if((DFS(a,b+p,p) && DFS(a+p,b,p)) || (DFS(a,b,p) && DFS(a+p,b+p,p)))
{
return 1;
}
return 0;
} int main()
{
while(scanf("%s",a)!=EOF)
{
scanf("%s",b);
int len = strlen(a);
int pk = DFS(a,b,len);
if(pk == 1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}

Codeforces Round #313 D. Equivalent Strings(DFS)的更多相关文章

  1. Codeforces Round 662 赛后解题报告(A-E2)

    Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...

  2. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  3. CodeForces 165C Another Problem on Strings(组合)

    A string is binary, if it consists only of characters "0" and "1". String v is a ...

  4. Codeforces Round #527 (Div. 3)F(DFS,DP)

    #include<bits/stdc++.h>using namespace std;const int N=200005;int n,A[N];long long Mx,tot,S[N] ...

  5. Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. 【Codeforces 723D】Lakes in Berland (dfs)

    海洋包围的小岛,岛内的有湖,'.'代表水,'*'代表陆地,给出的n*m的地图里至少有k个湖,求填掉面积尽量少的水,使得湖的数量正好为k. dfs找出所有水联通块,判断一下是否是湖(海水区非湖).将湖按 ...

  7. codeforces 805 E. Ice cream coloring(dfs)

    题目链接:http://codeforces.com/contest/805/problem/E 题意:你有n个节点,这个n个节点构成一棵树.每个节点拥有有si个类型的ice,同一个节点的ice互相连 ...

  8. codeforces 682C Alyona and the Tree(DFS)

    题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被 ...

  9. Codeforces Round #309 (Div. 1) A(组合数学)

    题目:http://codeforces.com/contest/553/problem/A 题意:给你k个颜色的球,下面k行代表每个颜色的球有多少个,规定第i种颜色的球的最后一个在第i-1种颜色的球 ...

随机推荐

  1. Oracle PLSQL Demo - 06.LOOP循环,以IF判断退出[IF in LOOP]

    declare v_sal ; begin loop v_sal :; dbms_output.put_line(v_sal); then exit; end if; end loop; end;

  2. innerHTML属性,outerHTML属性,textContent属性,innerText属性区别详解

    innerHTML属性用来读取或设置某个节点内的HTML代码. outerHTML属性用来读取或设置HTML代码时,会把节点本身包括在内. textContent属性用来读取或设置节点包含的文本内容. ...

  3. tomcat Can't create cache file!

    ) at javax.imageio.ImageIO.write(ImageIO.java:1558) ... 119 more Caused by: java.io.IOException: 系统找 ...

  4. c++之——template模板函数

    为了实现与数据类型无关的编程,模板应运而生: #include<iostream> #include<string.h> using namespace std; templa ...

  5. RSA算法工具

    RSA算法工具-生成密钥对(生成密钥对) RSA算法工具-解析密钥对(导入密钥对,解析密钥对) RSA测试工具-计算分量(输入P,Q,E,计算出N,DP,DQ,Qinv)

  6. 【Unity笔记】常见集合类System.Collections

    ArrayList:长度可变数组,不限定类型 ArrayList al = new ArrayList(); ↓ List:替代ArrayList,限定类型 List list = new List& ...

  7. yum命令与使用

    check          Check for problems in the rpmdbcheck-update   Check for available package updatesclea ...

  8. 【springmvc笔记】第二课 环境搭建和第一个springmvc例子

    1. 开发工具准备 eclipse + jdk1.7 spring-framework-4.3.9.RELEASE 2. 新建Dynamic Web Project项目,命名为springmvc. 3 ...

  9. C++实现最少硬币兑换问题

    最少硬币兑换问题 #include<iostream> #include<fstream> using namespace std; int n,L; //n种硬币L长的数组 ...

  10. JPA多对多关联

    关于JPA多对多关系,这是使用学生与教师来表示.一个Student由多个Teacher教,同样一个Teacher也可以教多个学生.Student类如下: package com.yichun.bean ...