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.