This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <deque>
#include <chrono>
#include <cassert>
#include <bitset>
#include <random>
using namespace std;
typedef long long li;
typedef long double ld;
const li MAX = 3e5 + 5;
li inf = (li)3000000000;
li mod = (li)998244353;
li n, m;
string s, t;
void swp(li len) {
string a, b;
a = s;
for (int i = 0; i < len; i++) {
b.push_back(a.back());
a.pop_back();
}
s = b + a;
}
void pos() {
string a, b;
a = s;
b = t;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (a != b) {
cout << -1;
exit(0);
}
}
void solve() {
cin >> n >> m;
cin >> s >> t;
pos();
vector<li> ans;
for (int i = 0; i < n; i++) {
li ind;
for (int j = i; j < n; j++) {
if (s[j] == t[i]) {
ind = j;
break;
}
}
swp(n);
swp(ind);
swp(1);
ans.push_back(n);
ans.push_back(ind);
ans.push_back(1);
}
swp(n);
ans.push_back(n);
cout << ans.size() << "\n";
for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
int main() {
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ios::sync_with_stdio(0);
li q;
q = 1;
while (q--) solve();
return 0;
}
Compilation message (stderr)
A.cpp: In function 'void solve()':
A.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |