# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
114354 | sebinkim | Lock Puzzle (innopolis2018_final_A) | C++14 | 9 ms | 640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
char A[2020], B[2020];
int D[2020], E[2020];
vector <int> V;
int n, m;
void shift(int p)
{
reverse(A, A + n);
reverse(A + p, A + n);
V.push_back(p);
}
int main()
{
int i, j;
scanf("%d%d", &n, &m);
scanf("%s%s", A, B);
if(n & 1){
D[0] = 0;
for(i=1; i<n; i+=2){
reverse(D, D + i);
for(j=i; j>=1; j--) D[j] = D[j - 1];
D[i + 1] = i; D[0] = i + 1;
}
for(i=0; i<n; i++){
E[D[i]] = i;
}
for(i=0; i<n; i++){
if(A[i] == B[E[0]]) break;
}
shift(n - i - 1);
for(i=1; i<n; i+=2){
for(j=0; j<n-i; j++){
if(A[j] == B[E[i]]) break;
}
shift(n - j - 1); shift(n); shift(i);
for(j=i+1; j<n; j++){
if(A[j] == B[E[i + 1]]) break;
}
shift(n - j); shift(j - i - 1);
}
}
else{
for(i=0; i<n; i+=2){
reverse(D, D + i);
for(j=i; j>=1; j--) D[j] = D[j - 1];
D[i + 1] = i; D[0] = i + 1;
}
for(i=0; i<n; i++){
E[D[i]] = i;
}
for(i=0; i<n; i+=2){
for(j=0; j<n-i; j++){
if(A[j] == B[E[i]]) break;
}
shift(n - j - 1); shift(n); shift(i);
for(j=i+1; j<n; j++){
if(A[j] == B[E[i + 1]]) break;
}
shift(n - j); shift(j - i - 1);
}
}
for(i=0; i<n; i++){
if(A[i] != B[i]) break;
}
if(i < n){
printf("-1\n");
}
else{
printf("%d\n", V.size());
for(int &t: V) printf("%d ", t);
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | 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... |