Source:
S
o
u
r
c
e
:
Codeforces Round #467 (Div. 1)
Problem:
P
r
o
b
l
e
m
:
Shift(n)
S
h
i
f
t
(
n
)
操作使得字符串
p = αβ
p
=
α
β
变成
βRα
β
R
α
,其中
Length(β)=n
L
e
n
g
t
h
(
β
)
=
n
,最多进行
3∗n
3
∗
n
步操作,使得字符串
s
s
转变为
Idea:
I
d
e
a
:
假设当前字符串
s
s
形如,其中
b=suffix(t)
b
=
s
u
f
f
i
x
(
t
)
,
pb=suffix(t)
p
b
=
s
u
f
f
i
x
(
t
)
,
p
p
的下标为。先
Shift(n)
S
h
i
f
t
(
n
)
,
s=...p...bR
s
=
.
.
.
p
.
.
.
b
R
,再
Shift(x−1)
S
h
i
f
t
(
x
−
1
)
,
s=b..p
s
=
b
.
.
p
,最后
Shift(1)
S
h
i
f
t
(
1
)
,
s=pb...
s
=
p
b
.
.
.
Code:
C
o
d
e
:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define CLR(A, X) memset(A, X, sizeof(A))
#define bitcount(X) __builtin_popcountll(X)
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<char, int> PCI;
const double eps = 1e-10;
const double PI = acos(-1.0);
const auto INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
int dcmp(double x) { if(fabs(x) < eps) return 0; return x<0?-1:1; }
const int MAXN = 2e3+10;
char s[MAXN], t[MAXN];
int n;
vector<int> G;
void shift(int x) {
if(x == 0) return;
reverse(s, s+n);
reverse(s+x, s+n);
G.pb(x);
}
int main() {
scanf("%d%s%s", &n, s, t);
for(int i = 0; i < n; i++) {
int j = i;
while(j<n && s[j]!=t[n-i-1]) j++;
if(j == n) {
puts("-1");
exit(0);
}
shift(n);
shift(j);
shift(1);
}
printf("%d\n", G.size());
for(int x:G) {
printf("%d ", x);
}
return 0;
}