Lunch

시간 제한1초메모리 제한1024 MB

요약
n개의 잎이 있는 외길에서 두꺼비가 s에서 시작해 f에서 끝나며 모든 파리를 먹어야 하고, 한 칸 점프 횟수를 최소로 만들어야 한다.
난이도

보통10점 중 7점

유형
동적 계획법, 그리디, 수학, 구현
정답자
아직 제출이 없습니다

문제

The swamp looks like a narrow lane with length nn covered by floating leaves sized 11, numbered from 11 to nn with a fly sitting on the top of each. A little toad is sitting on one of the leaves instead of a fly. Its name is Kvait and it is about to have lunch. It can jump to the bordering leaf or jump it over to the next one in any direction. When landing it eats a fly. Kvait is already quite a big toad and the leaves are unstable so when it jumps away the leaf starts sinking.

In order to have lunch Kvait needs to eat all of the flies. It starts his journey from the leaf with number ss and has to finish on the leaf with number ff. Yet jumping to the bordering leaf takes more Kvait’s energy than skipping a leaf over. It is necessary to plan the toad’s movements to get lunch with minimal energy spent.

입력

Single line contains three integers nn, ss, ff (2≤n≤10,0002 \le n \le 10\\,000, 1≤s,f≤n1 \le s, f \le n) --- the number of leaves, number of a starting leaf and the number of the finish leaf respectively.

출력

Output the minimal number of jumps to the bordering leaves required for the toad to have lunch. If there is no way to eat up, output a single number −1-1.

예제1

  1. 예제 1

    입력
    4 1 2
    
    예상 출력
    1