CF1474A.Puzzle From the Future

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In the 20222022 year, Mike found two binary integers aa and bb of length nn (both of them are written only by digits 00 and 11) that can have leading zeroes. In order not to forget them, he wanted to construct integer dd in the following way:

  • he creates an integer cc as a result of bitwise summing of aa and bb without transferring carry, so cc may have one or more 22-s. For example, the result of bitwise summing of 01100110 and 11011101 is 12111211 or the sum of 011000011000 and 011000011000 is 022000022000;
  • after that Mike replaces equal consecutive digits in cc by one digit, thus getting dd. In the cases above after this operation, 12111211 becomes 121121 and 022000022000 becomes 020020 (so, dd won't have equal consecutive digits).

Unfortunately, Mike lost integer aa before he could calculate dd himself. Now, to cheer him up, you want to find any binary integer aa of length nn such that dd will be maximum possible as integer.

Maximum possible as integer means that 102>21102 \gt 21, 012<101012 \lt 101, 021=21021 = 21 and so on.

2022 年,Mike 找到了两个长度为 nn 的二进制整数 aa 和 bb(即它们仅由数字 00 和 11 组成),且允许有前导零。为了不忘记它们,他希望按如下方式构造一个整数 dd:

  • 他先将 aa 和 bb 进行无进位的按位加法,得到整数 cc;因此 cc 中可能包含一个或多个数字 22。例如,01100110 与 11011101 的无进位按位加法结果为 12111211;又如,011000011000 与 011000011000 的无进位按位加法结果为 022000022000;
  • 然后 Mike 将 cc 中所有相邻且相等的数字替换为单个该数字,从而得到 dd。在上述例子中,该操作将 12111211 变为 121121,将 022000022000 变为 020020(因此 dd 中不再含有相邻相等的数字)。

不幸的是,Mike 在计算出 dd 之前就丢失了整数 aa。现在,为了让他振作起来,你希望找出任意一个长度为 nn 的二进制整数 aa,使得最终得到的 dd 作为整数时尽可能大。

此处“尽可能大”是指按通常的十进制整数大小比较:例如 102>21102 > 21,012<101012 < 101,021=21021 = 21,等等。

输入格式

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

The first line of each test case contains the integer nn (1≤n≤1051 \leq n \leq 10^5) — the length of aa and bb.

The second line of each test case contains binary integer bb of length nn. The integer bb consists only of digits 00 and 11.

It is guaranteed that the total sum of nn over all tt test cases doesn't exceed 10510^5.

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

每个测试用例的第一行包含整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 数组 aa 和 bb 的长度。

每个测试用例的第二行包含一个长度为 nn 的二进制整数 bb。该整数 bb 仅由数字 00 和 11 组成。

保证所有 tt 个测试用例的 nn 值之和不超过 10510^5。

输出格式

For each test case output one binary integer aa of length nn. Note, that aa or bb may have leading zeroes but must have the same length nn.

对每个测试用例,输出一个长度为 nn 的二进制整数 aa。注意,aa 或 bb 可能含有前导零,但它们的长度必须均为 nn。

输入输出样例

  • 输入#1

    5
    1
    0
    3
    011
    3
    110
    6
    111000
    6
    001011

    输出#1

    1
    110
    100
    101101
    101110

说明/提示

In the first test case, b=0b = 0 and choosing a=1a = 1 gives d=1d = 1 as a result.

In the second test case, b=011b = 011 so:

  • if you choose a=000a = 000, cc will be equal to 011011, so d=01d = 01;
  • if you choose a=111a = 111, cc will be equal to 122122, so d=12d = 12;
  • if you choose a=010a = 010, you'll get d=021d = 021.
  • If you select a=110a = 110, you'll get d=121d = 121.

We can show that answer a=110a = 110 is optimal and d=121d = 121 is maximum possible.

In the third test case, b=110b = 110. If you choose a=100a = 100, you'll get d=210d = 210 and it's the maximum possible dd.

In the fourth test case, b=111000b = 111000. If you choose a=101101a = 101101, you'll get d=212101d = 212101 and it's maximum possible dd.

In the fifth test case, b=001011b = 001011. If you choose a=101110a = 101110, you'll get d=102121d = 102121 and it's maximum possible dd.

在第一个测试用例中,b=0b = 0,选择 a=1a = 1 可得结果 d=1d = 1。

在第二个测试用例中,b=011b = 011,因此:

  • 若选择 a=000a = 000,则 c=011c = 011,故 d=01d = 01;
  • 若选择 a=111a = 111,则 c=122c = 122,故 d=12d = 12;
  • 若选择 a=010a = 010,可得 d=021d = 021;
  • 若选择 a=110a = 110,可得 d=121d = 121。

可以证明,最优解为 a=110a = 110,此时 d=121d = 121 是可能的最大值。

在第三个测试用例中,b=110b = 110。若选择 a=100a = 100,可得 d=210d = 210,这是可能的最大 dd 值。

在第四个测试用例中,b=111000b = 111000。若选择 a=101101a = 101101,可得 d=212101d = 212101,这是可能的最大 dd 值。

在第五个测试用例中,b=001011b = 001011。若选择 a=101110a = 101110,可得 d=102121d = 102121,这是可能的最大 dd 值。

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

首页