CF1659B.Bit Flipping
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a binary string of length n . You have exactly k moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ( 0 becomes 1 , 1 becomes 0 ). You need to output the lexicographically largest string that you can get after using all k moves. Also, output the number of times you will select each bit. If there are multiple ways to do this, you may output any of them.
A binary string a is lexicographically larger than a binary string b of the same length, if and only if the following holds:
- in the first position where a and b differ, the string a contains a 1 , and the string b contains a 0 .
输入格式
The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases.
Each test case has two lines. The first line has two integers n and k ( 1≤n≤2⋅105 ; 0≤k≤109 ).
The second line has a binary string of length n , each character is either 0 or 1 .
The sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, output two lines.
The first line should contain the lexicographically largest string you can obtain.
The second line should contain n integers f1,f2,…,fn , where fi is the number of times the i -th bit is selected. The sum of all the integers must be equal to k .
输入输出样例
输入#1
6 6 3 100001 6 4 100011 6 0 000000 6 1 111001 6 11 101100 6 12 001110
输出#1
111110 1 0 0 2 0 0 111110 0 1 1 1 0 1 000000 0 0 0 0 0 0 100110 1 0 0 0 0 0 111111 1 2 1 3 0 4 111110 1 1 4 2 0 4
说明/提示
Here is the explanation for the first testcase. Each step shows how the binary string changes in a move.
- Choose bit 1 : 100001→111110 .
- Choose bit 4 : 111110→000101 .
- Choose bit 4 : 000101→111110 .
The final string is 111110 and this is the lexicographically largest string we can get.