#P1135. 奇怪的电梯

    ID: 135 远端评测题 1000ms 128MiB 尝试: 4 已通过: 2 难度: 5 上传者: 标签>模拟广度优先搜索,BFS深度优先搜索,DFS

奇怪的电梯

Description

Hehe, one day I had a dream about a very strange elevator. The elevator can stop at every floor of the building, and on floor ii ( 1iN1 \le i \le N ) there is a number KiK_i ( 0KiN0 \le K_i \le N ). The elevator has only four buttons: Open, Close, Up, and Down. The number of floors moved up or down equals the number on the current floor. Of course, if the move would be invalid, the corresponding button will not work. For example: 3,3,1,2,53, 3, 1, 2, 5 represents KiK_i ( K1=3K_1 = 3, K2=3K_2 = 3, ... ), starting from floor 11. On floor 11, pressing "Up" takes you to floor 44, and pressing "Down" does nothing because there is no floor 2-2. Then, what is the minimum number of button presses to get from floor AA to floor BB?

Input Format

Two lines in total.

The first line contains three positive integers separated by spaces, denoting N,A,BN, A, B ( 1N2001 \le N \le 200, 1A,BN1 \le A, B \le N ).

The second line contains NN non-negative integers separated by spaces, denoting KiK_i.

Output Format

One line: the minimum number of button presses. If it is impossible to reach, output -1.

5 1 5
3 3 1 2 5

3

Hint

For 100% of the testdata, 1N2001 \le N \le 200, 1A,BN1 \le A, B \le N, 0KiN0 \le K_i \le N.

There are 1616 test points in total. The first 1515 test points are worth 66 points each, and the last test point is worth 1010 points.

Translated by ChatGPT 5