第 78 场 AtCoder Grand Contest
C
AB 对 BA
AB vs. BA
AtCoder
⌀ 3611
原题
← B→

AB 对 BAAI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given a string $S$ of length $N$ consisting of A and B. Abel and Bart play a game using $S$. Starting with Abel, they take turns performing the following operation.

给定一个长度为 $N$、由 A 和 B 组成的字符串 $S$。Abel 和 Bart 使用 $S$ 进行游戏。Abel 先手,双方轮流进行以下操作。AI (CI翻译)

  • Abel chooses one substring AB of $S$ and deletes it.
  • Bart chooses one substring BA of $S$ and deletes it.
  • Abel 选择 $S$ 中的一个子串 AB 并将其删除。
  • Bart 选择 $S$ 中的一个子串 BA 并将其删除。
AI (CI翻译)

The person who cannot perform the operation on their turn loses, and the other person wins. Find the winner when both players act optimally.

轮到某位玩家时,如果无法进行操作,则该玩家输,另一位玩家获胜。假设双方都采取最优策略,求最终的获胜者。AI (CI翻译)

Solve $T$ test cases for each input.

对于每组输入,求解 $T$ 个测试用例。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \le T \le 2 \times 10^5$
  • $1 \le N \le 2 \times 10^5$
  • $S$ is a string of length $N$ consisting of A and B.
  • The sum of $N$ over the $T$ test cases is at most $2 \times 10^5$.
  • All input values are integers.
  • $1 \le T \le 2 \times 10^5$
  • $1 \le N \le 2 \times 10^5$
  • $S$ 是一个长度为 $N$、由 A 和 B 组成的字符串。
  • 所有测试用例的 $N$ 之和不超过 $2 \times 10^5$。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
AI (CI翻译)

Each test case is given in the following format:

每个测试用例按以下格式给出:AI (CI翻译)

N
S

N
S
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $T$ lines. The $i$-th line should contain Abel if Abel wins the $i$-th test case, and Bart otherwise.

输出 $T$ 行。第 $i$ 行如果第 $i$ 个测试用例由 Abel 获胜,则输出 Abel;否则输出 Bart。AI (CI翻译)

样例

Input #1
2
5
ABAAB
5
AABBA
Output #1
Abel
Bart
In the first test case, if Abel deletes the left `AB`, then $S=$ `AAB`, and Bart cannot perform the operation, so Abel wins. In the second test case, if Abel deletes `AB`, then $S=$ `ABA`. Next, if Bart deletes `BA`, then $S=$ `A`, and Abel cannot perform the operation, so Bart wins.
Input #2
3
7
BAABAAA
13
AABBAAAABABBA
20
ABAABABABBAAABBABABA
Output #2
Bart
Abel
Abel
题目信息
题号
agc078_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。