【24.34%】【codeforces 560D】Equivalent Strings
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的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【34.57%】【codeforces 557D】Vitaly and Cycle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【24.17%】【codeforces 721D】Maxim and Array
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【34.88%】【codeforces 569C】Primes or Palindromes?
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【22.73%】【codeforces 606D】Lazy Student
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【codeforces 793D】Presents in Bankopolis
[题目链接]:http://codeforces.com/contest/793/problem/D [题意] 给你n个点, 这n个点 从左到右1..n依序排; 然后给你m条有向边; 然后让你从中选出 ...
- 【codeforces 799D】Field expansion
[题目链接]:http://codeforces.com/contest/799/problem/D [题意] 给你长方形的两条边h,w; 你每次可以从n个数字中选出一个数字x; 然后把h或w乘上x; ...
随机推荐
- php学习笔记5
PHP 常量 常量值被定义后,在脚本的其他任何地方都不能被改变. 一个常量由英文字母.下划线.和数字组成,但数字不能作为首字母出现. (常量名不需要加 $ 修饰符). 注意: 常量在整个脚本中都可以使 ...
- Android学习笔记之Bitmap位图的缩放
位图的缩放也可以借助Matrix或者Canvas来实现. 通过postScale(0.5f, 0.3f)方法设置旋转角度,然后用createBitmap方法创建一个经过缩放处理的Bitmap对象,最后 ...
- HTML基础第十二讲---链接标志
转自:https://i.cnblogs.com/posts?categoryid=1121494 没有链接,WWW将失去存在的意义!WWW之所以受欢迎,乃在于她除了有精美的图文之外,更有方便且多样化 ...
- JavaScript---call()使用的一些疑问
疑问:在使用.call()时,调用对象到底是否可以直接拥有了被调用者的方法和属性? 这里输出结果为:ReferenceError: o is not defined function Person(n ...
- Android RGB颜色对比表
一 RGB颜色对照表: 注:内容来自http://rgb.phpddt.com/ 里面有在线颜色摄取器 #FFFFFF #FFFFF0 #FFFFE0 #FFFF0 ...
- ASP.NET MVC 入门4、Controller与Action
原帖地址:http://www.cnblogs.com/QLeelulu/archive/2008/10/04/1303672.html Controller是MVC中比較重要的一部分.差点儿全部的业 ...
- tensorflow compile
bazel build --spawn_strategy=standalone tensorflow/examples/label_image/...
- StackExchange.Redis 官方文档
原文:StackExchange.Redis 官方文档 时隔多年的翻译终于完成了第六个,也是很重要的的官方文档,是介绍有关链接管理,管道流水线和多路复用的 官方地址在这里:官方文档 下面做个汇总: S ...
- SQL判断空值、nvl处理与JOIN的使用
LIKE子句会影响查询性能,所以在明确知道字符个数时,应该使用'_',而不使用'%'. 判断空值/非空值 SELECT select_list FROM table_list/view_list WH ...
- 使用docker 搭建基础的 mysql 应用
mysql server是眼下比較流行的开源数据库server.以下介绍怎样使用docker来做一个mysql数据库服务 从站点直接 pull 一个 mysql 的镜像 core@localhost ...