Nosuri

发布时间: 2018年12月8日 20:11   最后更新: 2018年12月8日 20:12   时间限制: 1000ms   内存限制: 512M

Nosuri, a thief, wants to unlock a combination lock quickly, which consists of two concentric circle with a center $o$.

There are $n$ code positions with digits on the outer circle and $n$ input positions on the inner circle.

A code position $p$ corresponds to an input position $q$ if and only if $p$ is on the ray $oq$. Obviously, an input position's corresponding code position may change if the inner circle is rotated.

The lock will be unlocked if the digits on each input position and its corresponding code position are the same.

Nosuri can do two types of operations:

1. Rotate an input position by $\frac{2\pi}{10}$ clockwise or counter-clockwise. (As we all know, every input position in a combination lock is a regular decagon with 10 digits from 0 to 9.)

2. Rotate the inner circle by $\frac{2\pi}{n}$ clockwise or counter-clockwise.

The number of operations is umlimited. Specially, it can be 0.

Given the digits on each code position and the initial digits on each input position in the inner circle respectively, Nosuri wants to know the minimum number of operations in order to open up the combination clock.

The first line contains an integer $n(1 \le n \le 5000)$.

The second line contains $n$ digits. The $i$-th of them represents the digit on the $i$-th code position clockwise.

The third line contains $n$ digits. The $i$-th of them represents the initial digit on the $i$-th input position clockwise.

Initially, the $i$-th code position corresponds to the $i$-th input position.

Output a non-negative integer representing the minimum number of operations.

复制
3
2 9 5
5 1 0
3

The figure below illustrates the initial state. We first rotate the inner circle counterclockwise, then the input with digit $1$, finally the input with digit $0$ to unlock in three operations.

lock.png

2018 fdupc

2018 FDUPC 程序设计校赛现场赛(网络同步赛)