generated from projeto-de-algoritmos-2024/RepositorioTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
q4.cpp
35 lines (30 loc) · 907 Bytes
/
q4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//author: Natan Almeida
//B. Equivalent Strings
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define ii pair<int, int>
#define vi vector<int>
#define eb emplace_back
#define debug(x) cout << x << endl
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define so(x) sort(x.begin(), x.end())
#define rso(x) sort(x.rbegin(), x.rend())
string smallest(string s) {
if (s.length() % 2 == 1) return s;
string s1 = smallest(s.substr(0, s.length()/2));
string s2 = smallest(s.substr((s.length()/2), s.length()/2));
if (s1 < s2) return s1 + s2;
else return s2 + s1;
}
int main() { _
string s1, s2; cin >> s1 >> s2;
if(s1 == s2) return cout << "YES" << endl, 0;
cout << (smallest(s1) == smallest(s2) ? "YES" : "NO") << endl;
return 0;
}