QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB

#21383. היפוכים נעלמים

Statistics

Alice ו-Bob משחקים משחק על תמורה, כאשר Alice משחקת ראשונה.

סדרה באורך $n$ נקראת תמורה אם ורק אם כל מספר שלם מתוך $1, 2, \ldots, n$ מופיע בסדרה בדיוק פעם אחת.

בהתחלה, נתונה תמורה $a_1, a_2, \ldots, a_n$ באורך $n$. בכל רגע במהלך המשחק, הסדרה הנוכחית היא תמיד תמורה באורך כלשהו $m$. השחקנים משחקים בתורות, ובכל תור השחקן הנוכחי חייב לבחור אחת משתי הפעולות הבאות:

  • לבחור אינדקס $i$ ($1 \le i < m$) כך ש-$a_i > a_{i+1}$, ולהחליף בין $a_i$ ל-$a_{i+1}$;
  • לבחור אינדקס $i$ ($1 \le i < m$) כך ש-$a_{i+1} = a_i + 1$, למחוק את $a_i$ ואת $a_{i+1}$, ולאחר מכן למספר מחדש את האיברים הנותרים בהתאם לסדר היחסי שלהם: האיבר ה-$k$ בגודלו מבין האיברים הנותרים (מהקטן לגדול) ממוספר מחדש כ-$k$, כך שהסדרה הנותרת הופכת שוב לתמורה.

לדוגמה, נניח שהתמורה הנוכחית היא $[2, 3, 4, 1]$. ניתן למחוק את האיברים הסמוכים $2$ ו-$3$, מה שמשאיר $[4, 1]$; לאחר מספור מחדש, התמורה הופכת ל-$[2, 1]$.

שחקן שאינו יכול לבצע אף פעולה מפסיד במשחק. בהנחה שגם Alice וגם Bob משחקים באופן אופטימלי, קבעו מי המנצח.

קלט

כל בדיקה מכילה מספר מקרי בדיקה.

השורה הראשונה מכילה מספר שלם $T$ ($1 \le T \le 5000$), מספר מקרי הבדיקה.

עבור כל מקרה בדיקה:

  • השורה הראשונה מכילה מספר שלם $n$ ($1 \le n \le 5000$).
  • השורה השנייה מכילה $n$ מספרים שלמים $a_1, a_2, \ldots, a_n$. מובטח כי $a$ היא תמורה באורך $n$.

מובטח כי סכום ערכי $n$ על פני כל מקרי הבדיקה אינו עולה על $5000$.

פלט

עבור כל מקרה בדיקה, הדפיסו Alice אם Alice מנצחת; אחרת, הדפיסו Bob.

דוגמאות

קלט 1

5
1
1
2
1 2
2
2 1
4
2 4 1 3
5
5 1 4 2 3

פלט 1

Bob
Alice
Bob
Alice
Bob

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.