AT_agc078_c.AB vs. BA

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

  • Abel chooses one substring AB of SS and deletes it.
  • Bart chooses one substring BA of SS and deletes it.

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

Solve TT test cases for each input.

给你一个长度为 NN 的字符串 SS,仅由字符 A 和 B 组成。Abel 和 Bart 使用 SS 进行一场游戏。游戏从 Abel 开始,两人轮流执行以下操作:

  • Abel 选择 SS 中的一个子串 AB 并将其删除;
  • Bart 选择 SS 中的一个子串 BA 并将其删除。

无法在自己的回合执行操作的人输掉游戏,另一人获胜。当双方均以最优策略进行游戏时,请判断胜者。

对每组输入求解 TT 个测试用例。

输入格式

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

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN
SS

输入从标准输入中以如下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例以如下格式给出:

NN
SS

输出格式

Output TT lines. The ii-th line should contain Abel if Abel wins the ii-th test case, and Bart otherwise.

输出 TT 行。第 ii 行应包含 Abel(如果 Abel 赢得第 ii 个测试用例),否则包含 Bart。

输入输出样例

  • 输入#1

    2
    5
    ABAAB
    5
    AABBA

    输出#1

    Abel
    Bart
  • 输入#2

    3
    7
    BAABAAA
    13
    AABBAAAABABBA
    20
    ABAABABABBAAABBABABA

    输出#2

    Bart
    Abel
    Abel

说明/提示

Sample 1 Explanation:
In the first test case, if Abel deletes the left AB, then S=S= AAB, and Bart cannot perform the operation, so Abel wins.

In the second test case, if Abel deletes AB, then S=S= ABA. Next, if Bart deletes BA, then S=S= A, and Abel cannot perform the operation, so Bart wins.

Constraints

  • 1≤T≤2×1051 \le T \le 2 \times 10^5
  • 1≤N≤2×1051 \le N \le 2 \times 10^5
  • SS is a string of length NN consisting of A and B.
  • The sum of NN over the TT test cases is at most 2×1052 \times 10^5.
  • All input values are integers.

样例 1 解释:
在第一个测试用例中,若 Abel 删除左侧的 AB,则 S=S= AAB,此时 Bart 无法执行操作,因此 Abel 获胜。

在第二个测试用例中,若 Abel 删除 AB,则 S=S= ABA。接下来,若 Bart 删除 BA,则 S=S= A,此时 Abel 无法执行操作,因此 Bart 获胜。

约束条件

  • 1≤T≤2×1051 \le T \le 2 \times 10^5
  • 1≤N≤2×1051 \le N \le 2 \times 10^5
  • SS 是一个长度为 NN 的字符串,仅由字符 A 和 B 组成。
  • 所有 TT 个测试用例的 NN 值之和不超过 2×1052 \times 10^5。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页