CF1659B.Bit Flipping

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a binary string of length nn. You have exactly kk moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped (00 becomes 11, 11 becomes 00). You need to output the lexicographically largest string that you can get after using all kk 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 aa is lexicographically larger than a binary string bb of the same length, if and only if the following holds:

  • in the first position where aa and bb differ, the string aa contains a 11, and the string bb contains a 00.

给你一个长度为 nn 的二进制字符串。你恰好有 kk 次操作。每次操作中,你必须选择某一位。除该位外,其余所有位的状态均被翻转(即 00 变为 11,11 变为 00)。你需要输出经过全部 kk 次操作后能得到的字典序最大的字符串,并输出每一位被选中的次数。若存在多种方案,输出任意一种即可。

当且仅当满足以下条件时,二进制字符串 aa 的字典序大于相同长度的二进制字符串 bb:

  • 在 aa 与 bb 首次出现差异的位置上,aa 中该位为 11,而 bb 中该位为 00。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

Each test case has two lines. The first line has two integers nn and kk (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5; 0≤k≤1090 \leq k \leq 10^9).

The second line has a binary string of length nn, each character is either 00 or 11.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 表示测试用例的数量。

每个测试用例包含两行。第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5;0≤k≤1090 \leq k \leq 10^9)。

第二行包含一个长度为 nn 的二进制字符串,其中每个字符为 00 或 11。

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

输出格式

For each test case, output two lines.

The first line should contain the lexicographically largest string you can obtain.

The second line should contain nn integers f1,f2,…,fnf_1, f_2, \ldots, f_n, where fif_i is the number of times the ii-th bit is selected. The sum of all the integers must be equal to kk.

对于每个测试用例,输出两行。

第一行应包含你能得到的字典序最大的字符串。

第二行应包含 nn 个整数 f1,f2,…,fnf_1, f_2, \ldots, f_n,其中 fif_i 表示第 ii 位被选中的次数。所有整数之和必须等于 kk。

输入输出样例

  • 输入#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 11: 1‾00001→1‾11110\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}.
  • Choose bit 44: 1111‾10→0001‾01\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{red}{\underline{1}}\color{blue}{01}.
  • Choose bit 44: 0001‾01→1111‾10\color{red}{000\underline{1}01} \rightarrow \color{blue}{111}\color{red}{\underline{1}}\color{blue}{10}.

The final string is 111110111110 and this is the lexicographically largest string we can get.

以下是第一个测试用例的解释。每一步都展示了二进制字符串在一次操作中如何变化。

  • 选择第 11 位:1‾00001→1‾11110\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}。
  • 选择第 44 位:1111‾10→0001‾01\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{red}{\underline{1}}\color{blue}{01}。
  • 选择第 44 位:0001‾01→1111‾10\color{red}{000\underline{1}01} \rightarrow \color{blue}{111}\color{red}{\underline{1}}\color{blue}{10}。

最终字符串为 111110111110,这也是我们能得到的字典序最大的字符串。

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

首页