#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
string a, b;
cin >> a >> b;
int am[26] = {0};
for(auto& x : a) am[x - 'a']++;
for(auto& x : b) am[x - 'a']--;
for(int i = 0; i < n; i++)
if(am[i] != 0) {
cout << -1;
return 0;
}
vector<int> ans;
for(int i = 0; i < n; i++) {
if(a[i] == b[i]) continue;
if(a.back() == b[i]) {
ans.pb(n - i);
string p = a.substr(0, i), s = a.substr(i, n - i);
reverse(all(s));
a = p + s;
} else {
for(int j = i + 1; j < n; j++)
if(a[j] == b[i]) {
ans.pb(n - j);
string p = a.substr(0, j), s = a.substr(j, n - j);
reverse(all(s));
a = p + s;
break;
}
ans.pb(n - i);
string p = a.substr(0, i), s = a.substr(i, n - i);
reverse(all(s));
a = p + s;
}
}
if(ans.size() > m) { cout << -1; return 0; }
cout << ans.size() << endl;
for(auto& x : ans) cout << x << ' ';
return 0;
}
/*
*/
Compilation message
A.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
A.cpp: In function 'int main()':
A.cpp:85:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
85 | if(ans.size() > m) { cout << -1; return 0; }
| ~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
[n = 1, m = 10000], OK, 0 operations |
2 |
Correct |
1 ms |
364 KB |
[n = 2, m = 10000], OK, 1 operations |
3 |
Incorrect |
1 ms |
364 KB |
S is not equal after all operations: S = kugxnjpp, T = jgppnuxk |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
[n = 1, m = 10000], OK, 0 operations |
2 |
Correct |
1 ms |
364 KB |
[n = 2, m = 10000], OK, 1 operations |
3 |
Incorrect |
1 ms |
364 KB |
S is not equal after all operations: S = kugxnjpp, T = jgppnuxk |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
[n = 1, m = 10000], OK, 0 operations |
2 |
Correct |
1 ms |
364 KB |
[n = 2, m = 10000], OK, 1 operations |
3 |
Incorrect |
1 ms |
364 KB |
S is not equal after all operations: S = kugxnjpp, T = jgppnuxk |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
[n = 1, m = 10000], OK, 0 operations |
2 |
Correct |
1 ms |
364 KB |
[n = 2, m = 10000], OK, 1 operations |
3 |
Incorrect |
1 ms |
364 KB |
S is not equal after all operations: S = kugxnjpp, T = jgppnuxk |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
[n = 1, m = 10000], OK, 0 operations |
2 |
Correct |
1 ms |
364 KB |
[n = 2, m = 10000], OK, 1 operations |
3 |
Incorrect |
1 ms |
364 KB |
S is not equal after all operations: S = kugxnjpp, T = jgppnuxk |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
[n = 1, m = 10000], OK, 0 operations |
2 |
Correct |
1 ms |
364 KB |
[n = 2, m = 10000], OK, 1 operations |
3 |
Incorrect |
1 ms |
364 KB |
S is not equal after all operations: S = kugxnjpp, T = jgppnuxk |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
[n = 1, m = 10000], OK, 0 operations |
2 |
Correct |
1 ms |
364 KB |
[n = 2, m = 10000], OK, 1 operations |
3 |
Incorrect |
1 ms |
364 KB |
S is not equal after all operations: S = kugxnjpp, T = jgppnuxk |
4 |
Halted |
0 ms |
0 KB |
- |