普普通通的暴力
Python 代码
n = int(input())
a, b = [], []
for i in range(n):
a.append(int(input()))
for i in range(n):
b.append(int(input()))
st = [0] * n
count, res = 0, 0
for i in range(n):
if st[i]:
continue
index = b.index(a[i])
count += (index != i)
ans = 0
while index != i:
x = a[index]
st[index] = 1
while b[index] != x:
index = (index + 1) % n
ans += 1
res = max(res, ans)
print(count, res + 1 if res else -1)