Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#pragma GCC optimize("Ofast")
- #include <bits/stdc++.h>
- #define ld long double
- #define pnode node*
- typedef long long ll;
- using namespace std;
- ll n;
- string s, t;
- vector < ll > cnts(1000), cntt(1000);
- void no(){
- cout << -1 << "\n";
- exit(0);
- }
- vector < ll > ans;
- void mv(ll pos){
- if(pos == n)return;
- ll len = (n - 1) - pos + 1;
- ans.push_back(len);
- string cs = "";
- for(ll i = n - 1; i >= pos; --i){
- cs.push_back(s[i]);
- }
- for(ll i = 0; i < pos; ++i){
- cs.push_back(s[i]);
- }
- s = cs;
- }
- ll find_pref(char a){
- for(ll i = 0; i < n; ++i){
- if(s[i] == a){
- return i;
- }
- }
- assert(0);
- }
- ll find_suff(char a){
- for(ll i = n - 1; i >= 0; --i){
- if(s[i] == a){
- return i;
- }
- }
- assert(0);
- }
- void solve(){
- cin >> n;
- cin >> s >> t;
- for(ll i = 0; i < n; ++i){
- cnts[s[i]]++;
- cntt[t[i]]++;
- }
- for(ll i = 0; i < 1000; ++i){
- if(cnts[i] != cntt[i]){
- no();
- }
- }
- ll pos = n / 2;
- char cur = t[pos];
- ll spos = find_pref(cur);
- mv(spos + 1);
- bool rev = 0;
- cerr << s << " " << t << "\n";
- for(ll i = 1; i <= n; ++i){
- ll posl = pos - i;
- ll posr = pos + i;
- if(posl < 0 || posr >= n)break;
- if(!rev)swap(posl, posr);
- ll CSZ = 2 * (i - 1) + 1;
- ll fposl = find_pref(t[posl]);
- mv(fposl + 1);
- mv(0);
- mv(n - CSZ);
- ll fposr = find_suff(t[posr]);
- ll BSZ = n - fposr - 1;
- ll ASZ = fposr - CSZ - 1;
- mv(n - BSZ - 1);
- mv(n - ASZ);
- rev ^= 1;
- cerr << s << "\n";
- cerr << t << "\n";
- cerr << "\n\n";
- }
- cout << s << "\n";
- cout << t << "\n";
- }
- signed main(){
- ll t = 1;
- srand(time(0));
- cout << fixed << setprecision(20);
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- #ifdef DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- #endif
- while(t--){
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement