QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB

#21383. 消えゆく転倒数

Statistics

Alice と Bob は順列を用いたゲームをしており、Alice が先手です。

長さ $n$ の数列は、$1, 2, \ldots, n$ の各整数がその数列にちょうど 1 回ずつ現れるとき、かつそのときに限り順列と呼ばれます。

最初、長さ $n$ の順列 $a_1, a_2, \ldots, a_n$ が与えられます。ゲームのどの時点においても、現在の数列は常にある長さ $m$ の順列となっています。プレイヤーは交互に手番を行い、各手番において手番のプレイヤーは以下の 2 つの操作のうちいずれか 1 つを選ばなければなりません:

  • $a_i > a_{i+1}$ を満たす添字 $i$($1 \le i < m$)を選び、$a_i$ と $a_{i+1}$ を入れ替える;
  • $a_{i+1} = a_i + 1$ を満たす添字 $i$($1 \le i < m$)を選び、$a_i$ と $a_{i+1}$ を削除し、残った要素を相対的な順序に従って番号を振り直す。すなわち、残った要素の中で $k$ 番目に小さい要素を $k$ に置き換え、残った数列が再び順列になるようにする。

例えば、現在の順列が $[2, 3, 4, 1]$ であるとします。隣接する要素 $2$ と $3$ を削除すると $[4, 1]$ が残り、番号を振り直すと順列は $[2, 1]$ になります。

いかなる操作も行えなくなったプレイヤーはゲームに負けます。Alice と Bob の両方が最適に行動すると仮定したとき、勝者を判定してください。

入力

各テストは複数のテストケースを含む。

1 行目には、テストケースの個数を表す整数 $T$($1 \le T \le 5000$)が与えられます。

各テストケースについて:

  • 1 行目には整数 $n$($1 \le n \le 5000$)が与えられます。
  • 2 行目には $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.