CF2241F.A Bit Odd

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alice and Bob have got a binary∗^{\text{∗}} string ss of length nn. They have decided to play a game on it, taking turns alternately, with Alice moving first.

In each move, the player must select a subsequence†^{\text{†}} which has an odd number of inversions‡^{\text{‡}} and delete it. The player who cannot make a move loses.

Determine who wins the game, assuming both players play optimally.

∗^{\text{∗}}A binary string is a string that consists only of the characters 0\texttt{0} and 1\texttt{1}.

†^{\text{†}}A sequence aa is a subsequence of a string bb if aa can be obtained from bb by the deletion of several (possibly zero or all) characters.

‡^{\text{‡}}An inversion in a binary string ss is a pair of indices (i,j)(i, j) such that i<ji \lt j and si=1s_i = \texttt{1} and sj=0s_j = \texttt{0}.

爱丽丝和鲍勃得到了一个长度为 nn 的二进制∗^{\text{∗}}字符串 ss。他们决定在该字符串上进行一场游戏,轮流行动,爱丽丝先手。

在每一轮中,当前玩家必须选择一个具有奇数个逆序对‡^{\text{‡}}的子序列†^{\text{†}}并将其删除。无法进行操作的玩家判负。

假设双方均采取最优策略,请判断谁将获胜。

∗^{\text{∗}}二进制字符串是指仅由字符 0\texttt{0} 和 1\texttt{1} 组成的字符串。

†^{\text{†}}若序列 aa 可通过对字符串 bb 删除若干(可能为零个或全部)字符而得到,则称 aa 是 bb 的一个子序列。

‡^{\text{‡}}二进制字符串 ss 中的一个逆序对是指一对下标 (i,j)(i, j),满足 i<ji \lt j,且 si=1s_i = \texttt{1}、sj=0s_j = \texttt{0}。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Description of each test case follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2\cdot10^5) — the length of the binary string ss.

The second line of each test case contains a binary string ss of length nn. It is guaranteed that each character of ss is either 0\texttt{0} or 1\texttt{1}.

It is guaranteed that the sum of nn over all the test cases does not exceed 2⋅1052\cdot10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。接下来是每个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2\cdot10^5)—— 二进制字符串 ss 的长度。

每个测试用例的第二行包含一个长度为 nn 的二进制字符串 ss。保证 ss 中的每个字符均为 0\texttt{0} 或 1\texttt{1}。

保证所有测试用例的 nn 值之和不超过 2⋅1052\cdot10^5。

输出格式

For each test case, print Alice\texttt{Alice} if Alice wins the game and Bob\texttt{Bob} otherwise.

对于每个测试用例,如果 Alice 获胜则输出 Alice\texttt{Alice},否则输出 Bob\texttt{Bob}。

输入输出样例

  • 输入#1

    3
    5
    10101
    4
    0100
    6
    011001

    输出#1

    Alice
    Alice
    Bob

说明/提示

For the first test case, Alice can choose the entire string as it has an odd number of inversions. Now, Bob is left with an empty string, and he cannot make a move. Thus, Alice wins.

For the second test case, Alice can choose the subsequence formed by the characters at indices 11, 22, and 44, i.e., 010\texttt{010}. Bob is then left with the character at index 33, namely 0\texttt{0}, which has 00 inversions (an even number). Therefore, Bob cannot choose a subsequence with an odd number of inversions, so Alice wins.

For the third test case, it can be shown that Bob can guarantee a win irrespective of Alice's first move.

对于第一个测试用例,Alice 可以选择整个字符串,因为该字符串具有奇数个逆序对。此时 Bob 面对的是一个空字符串,无法进行任何操作。因此 Alice 获胜。

对于第二个测试用例,Alice 可以选择由下标 11、22 和 44 处的字符构成的子序列,即 010\texttt{010}。此时 Bob 剩余的字符位于下标 33 处,即 0\texttt{0},其逆序对数量为 00(偶数)。因此 Bob 无法选出一个具有奇数个逆序对的子序列,故 Alice 获胜。

对于第三个测试用例,可以证明:无论 Alice 的第一步如何操作,Bob 均能确保获胜。

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

首页