CF1884B.Haunted House

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a number in binary representation consisting of exactly nn bits, possibly, with leading zeroes. For example, for n=5n = 5 the number 66 will be given as 0011000110 , and for n=4n = 4 the number 99 will be given as 10011001 .

Let's fix some integer ii such that 1in1 \le i \le n . In one operation you can swap any two adjacent bits in the binary representation. Your goal is to find the smallest number of operations you are required to perform to make the number divisible by 2i2^i , or say that it is impossible.

Please note that for each 1in1 \le i \le n you are solving the problem independently.

输入格式

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

The first line of each test case contains one integer nn ( 1n1051 \le n \le 10^5 ) — the length of the binary representation of the number.

The second line of each test case contains a string of length nn , consisting of 00 and 11 , — the binary representation of the number.

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

输出格式

For each test case, for each 1in1 \le i \le n output the smallest number of operations required to make the number divisible by 2i2^i , or output 1-1 if it is impossible.

输入输出样例

  • 输入#1

    6
    1
    1
    2
    01
    3
    010
    5
    10101
    7
    0000111
    12
    001011000110

    输出#1

    -1 
    1 -1 
    0 1 -1 
    1 3 -1 -1 -1 
    3 6 9 12 -1 -1 -1 
    0 2 4 6 10 15 20 -1 -1 -1 -1 -1

说明/提示

In the first test case, we cannot swap any elements, and the number 11 is not divisible by 22 .

In the second test case, the initial number is 11 . It is not divisible by 22 , but if we perform the operation, then we obtain the number with binary representation 1010 , which is equal to 22 in decimal representation, thus, it is divisible by 22 . But this number is not divisible by 44 and we cannot obtain any other number using the operations.

In the third test case, the initial number is 22 . For i=1i = 1 we do not have to perform any operations since the initial number is divisible by 22 . For i=2i = 2 we can perform one operation swapping the first two bits (we would obtain 100100 in binary representation, which corresponds to number 44 ). There is no answer for i=3i = 3 .

首页