QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100

#18661. 午餐

Statistics

沼澤看起來像一條長度為 $n$ 的狹窄通道,上面覆蓋著大小為 $1$ 的漂浮葉片,編號從 $1$ 到 $n$,每片葉子上都停著一隻蒼蠅。其中一片葉子上坐著一隻小蟾蜍,而不是蒼蠅。牠叫 Kvait,正準備吃午餐。牠可以向任一方向跳到相鄰的葉子上,或越過相鄰的葉子跳到下一片。每次落下時,牠就吃掉一隻蒼蠅。Kvait 已經是一隻相當大的蟾蜍,而葉子很不穩定,因此牠一跳離葉子,葉子就開始下沉。

為了吃上午餐,Kvait 必須吃掉所有蒼蠅。牠從編號為 $s$ 的葉子出發,而且必須在編號為 $f$ 的葉子上結束。然而,跳到相鄰的葉子比越過一片葉子更消耗 Kvait 的體力。必須規劃蟾蜍的移動方式,讓牠以最少的體力消耗吃上午餐。

輸入格式

唯一的一行包含三個整數 $n$、$s$、$f$($2 \le n \le 10\,000$,$1 \le s,f \le n$),依次表示葉子的數量、起點葉子的編號和終點葉子的編號。

輸出格式

輸出蟾蜍吃上午餐所需的、跳到相鄰葉子的最少次數。如果無法吃光所有蒼蠅,輸出一個數 $-1$。

範例

輸入格式 1

4 1 2

輸出格式 1

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.