CF2192B.Flipping Binary String

入门

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a binary string ss of length nn. You can perform the following operation on the string:

  • Choose an index ii, and flip the bit present at all other indices except for the index ii. In other words, choose an integer ii (1≤i≤n1 \le i \le n), and for all jj such that 1≤j≤n1 \le j \le n and j≠ij \ne i, if sj=0s_j = 0, then set sj:=1s_j:=1, otherwise set sj:=0s_j:=0.

You can perform the operation any number of times, but each index can be chosen by at most one operation.

Your task is to make all bits present in the string ss equal 00, or report that it is impossible to do so. You don't have to minimize the number of operations.

给你一个长度为 nn 的二进制字符串 ss。你可以对字符串执行以下操作:

  • 选择一个下标 ii,并将除下标 ii 外所有位置上的比特翻转。换言之,选择一个整数 ii(满足 1≤i≤n1 \le i \le n),并对所有满足 1≤j≤n1 \le j \le n 且 j≠ij \ne i 的 jj,若 sj=0s_j = 0,则令 sj:=1s_j := 1;否则令 sj:=0s_j := 0。

你可以执行该操作任意多次,但每个下标最多只能被选中一次。

你的任务是使字符串 ss 中所有比特均变为 00,或者判断这是不可能的。你无需最小化操作次数。

输入格式

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 contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5).

The second line of each test case contains the binary string ss of length nn.

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)。

每个测试用例的第二行包含一个长度为 nn 的二进制字符串 ss。

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

输出格式

For each test case, output −1-1 if it is impossible to transform all bits to 00. Otherwise, output two lines in the following format:

  • In the first line, print the number of operations xx (0≤x≤n0 \leq x \leq n).
  • In the second line of each test case, print xx numbers – the indices you select in each operation in order. You should guarantee that each index is chosen at most once.

If there are multiple possible solutions, you may output any.

对于每个测试用例,如果无法将所有位变为 00,则输出 −1-1;否则,按以下格式输出两行:

  • 第一行输出操作次数 xx(0≤x≤n0 \leq x \leq n);
  • 每个测试用例的第二行输出 xx 个数字——即每次操作所选的下标(按操作顺序)。需保证每个下标至多被选择一次。

若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#1

    4
    3
    101
    3
    100
    4
    0000
    4
    1010

    输出#1

    1
    2 
    -1
    0
    2
    1 3

说明/提示

In the first test case, performing the operation on index 22 means flipping bits present at index 11 and 33. So the new string formed will be 000000.

In the second test case, it can be shown that we cannot make string aa equal to 000000 using the described operations.

在第一个测试用例中,对索引 22 执行操作意味着翻转位于索引 11 和 33 处的比特位。因此,得到的新字符串为 000000。

在第二个测试用例中,可以证明:无法通过题目所述的操作将字符串 aa 变为 000000。

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

首页