Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- using namespace std;
- //Temir Askhat
- #define ll long long
- #define ull unsigned long long
- #define pb push_back
- #define sz size()
- #define sqr(x) ((x) * (x))
- #define mp make_pair
- #define F first
- #define S second
- #define all(c) c.begin(), c.end()
- #define rall(c) c.rbegin(), c.rend()
- #define tr(container, it) \
- for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
- #define present(container, element) (container.find(element) != container.end()) // set, map
- #define cpresent(container, element) (find(all(container), element) != container.end())\
- vector<int> prefix(string str) {
- int n = str.size();
- vector<int> p(n);
- int j = 0;
- for(int i = 1; i < n; i++) {
- while(j > 0 && str[i] != str[j])
- j = p[j - 1];
- if(str[i] == str[j]) j++;
- p[i] = j;
- }
- return p;
- }
- int main() {
- #ifndef ONLINE_JUDGE
- freopen("in", "r", stdin); freopen("out", "w", stdout);
- #endif
- int n;
- cin >> n;
- string s, t;
- cin >> s >> t;
- string cur = s + t;
- vector<int> v = prefix(cur);
- while(v[v.sz - 1] != 0) {
- if(v[v.sz - 1] == 0) {
- cout << "NO";
- return 0;
- }
- int end = v[v.sz - 1];
- cur.erase(0, end);
- string current = "";
- //cout << endl;
- for (int i = 0; i < cur.sz - end ; ++i) {
- current += cur[i];
- }
- //cout << "current " << current << endl;
- cur = current;
- // cout << "cur " << cur << endl;
- if(cur.sz == 0) {
- cout << "YES";
- return 0;
- }
- v = prefix(cur);
- }
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement