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.