CF2190A.Sorting Game

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alice and Bob play a game on a binary string ss of length nn (a string consisting only of characters 0\mathtt{0} and 1\mathtt{1}). Alice moves first, and the players take alternate turns.

In one turn, a player chooses a sequence of indices i1,i2,…,imi_1, i_2, \ldots, i_m (1≤i1<i2<…<im≤n1 \le i_1 \lt i_2 \lt \ldots \lt i_m \le n) such that the characters at these positions form a non-increasing sequence (that is, si1≥si2≥…≥sims_{i_1} \ge s_{i_2} \ge \ldots \ge s_{i_m}). The player then rearranges the characters at these positions to be sorted in non-decreasing order.

Formally, let the chosen characters consist of zz zeros and oo ones (where z+o=mz + o = m). The move replaces the characters at positions i1,i2,…,imi_1, i_2, \ldots, i_m with a sequence of zz zeros followed by oo ones. A move is valid if and only if it strictly modifies the string ss (which implies z≥1z \ge 1 and o≥1o \ge 1).

The player who cannot make a valid move loses.

Assuming both players play optimally, determine the winner. If Alice wins, output a valid first move that is part of a winning strategy.

Alice 和 Bob 在一个长度为 nn 的二进制字符串 ss(即仅由字符 0\mathtt{0} 和 1\mathtt{1} 组成的字符串)上进行一场游戏。Alice 先手,双方轮流行动。

在一轮中,一名玩家选择一组下标序列 i1,i2,…,imi_1, i_2, \ldots, i_m(满足 1≤i1<i2<…<im≤n1 \le i_1 \lt i_2 \lt \ldots \lt i_m \le n),使得这些位置上的字符构成一个非递增序列(即 si1≥si2≥…≥sims_{i_1} \ge s_{i_2} \ge \ldots \ge s_{i_m})。然后该玩家将这些位置上的字符重新排列为非递减顺序。

形式化地,设所选字符中包含 zz 个 0\mathtt{0} 和 oo 个 1\mathtt{1}(其中 z+o=mz + o = m)。该操作将位置 i1,i2,…,imi_1, i_2, \ldots, i_m 上的字符替换为 zz 个 0\mathtt{0} 后接 oo 个 1\mathtt{1}。当且仅当该操作严格改变了字符串 ss(这意味着 z≥1z \ge 1 且 o≥1o \ge 1)时,该操作才是合法的。

无法进行合法操作的玩家判负。

假设双方均以最优策略进行游戏,请判断获胜方。若 Alice 获胜,请输出一个属于必胜策略的合法首步操作。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

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

The second line of each test case contains a binary string ss of length nn consisting of only characters 0\mathtt{0} and 1\mathtt{1}.

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

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

每个测试用例的第二行包含一个长度为 nn 的二进制字符串 ss,该字符串仅由字符 0\mathtt{0} 和 1\mathtt{1} 组成。

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

输出格式

For each test case, output one or three lines:

  • If Bob wins with optimal play, print a single line containing "Bob".
  • Otherwise, print three lines. On the first line print "Alice". On the second line print an integer mm (2≤m≤n2 \le m \le n), and on the third line print mm distinct integers i1,i2,…,imi_1, i_2, \ldots, i_m (1≤i1<i2<…<im≤n1 \le i_1 \lt i_2 \lt \ldots \lt i_m \le n) — the indices chosen for Alice's first move.

The sequence of indices you print must form a valid move according to the rules described in the statement. The indices must be printed in increasing order. If there are multiple winning moves, you may output any of them.

对于每个测试用例,输出一行或三行:

  • 如果鲍勃在双方均采取最优策略时获胜,则输出一行,内容为 "Bob"。
  • 否则,输出三行:第一行输出 "Alice";第二行输出一个整数 mm(满足 2≤m≤n2 \le m \le n);第三行输出 mm 个互不相同的整数 i1,i2,…,imi_1, i_2, \ldots, i_m(满足 1≤i1<i2<…<im≤n1 \le i_1 \lt i_2 \lt \ldots \lt i_m \le n),表示爱丽丝第一步所选元素的下标。

你所输出的下标序列必须符合题目描述中规定的合法操作要求,且这些下标必须按严格递增顺序输出。若存在多个必胜操作,任选其一输出即可。

输入输出样例

  • 输入#1

    3
    3
    000
    2
    10
    3
    101

    输出#1

    Bob
    Alice
    2
    1 2 
    Alice
    2
    1 2

说明/提示

In the first example, there is no way to make a move after which ss will change, so Bob wins immediately.

In the third example, Alice can choose a subsequence [1,2][1, 2] and sort it, after which ss will turn into 011\mathtt{011}. After that, Bob can't make a move, so Alice wins.

在第一个例子中,不存在任何操作能使 ss 发生变化,因此鲍勃立即获胜。

在第三个例子中,爱丽丝可以选择子序列 [1,2][1, 2] 并将其排序,之后 ss 将变为 011\mathtt{011}。此后鲍勃无法进行任何操作,因此爱丽丝获胜。

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

首页