CF1369B.AccurateLee

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...

The string ss he found is a binary string of length nn (i. e. string consists only of 0-s and 1-s).

In one move he can choose two consecutive characters sis_i and si+1s_{i+1}, and if sis_i is 1 and si+1s_{i + 1} is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.

Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string ss as clean as possible. He thinks for two different strings xx and yy, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.

Now you should answer tt test cases: for the ii-th test case, print the cleanest possible string that Lee can get by doing some number of moves.

Small reminder: if we have two strings xx and yy of the same length then xx is lexicographically smaller than yy if there is a position ii such that x1=y1x_1 = y_1, x2=y2x_2 = y_2,..., xi−1=yi−1x_{i - 1} = y_{i - 1} and xi<yix_i \lt y_i.

Lee 在为聚会打扫房间时,在地毯下发现了一串混乱的字符串。现在他希望以一种精确而时尚的方式将其清理干净……

他发现的字符串 ss 是一个长度为 nn 的二进制字符串(即仅由 0 和 1 构成的字符串)。

在一次操作中,他可以选择两个相邻的字符 sis_i 和 si+1s_{i+1};若 si=1s_i = 1 且 si+1=0s_{i + 1} = 0,则他可以恰好删除其中的一个字符(他可任选删除哪一个,但不能同时删除两个字符)。删除后字符串会缩短。

Lee 可以执行任意次数(包括零次)的操作,他希望将字符串 ss 清理得尽可能“干净”。他认为:对于两个不同的字符串 xx 和 yy,长度更短的字符串更干净;若长度相同,则字典序更小的字符串更干净。

现在你需要回答 tt 组测试用例:对第 ii 个测试用例,输出 Lee 经过若干次操作后所能得到的最干净的字符串。

小提示:若两个字符串 xx 和 yy 长度相同,则当存在某个位置 ii,使得 x1=y1x_1 = y_1, x2=y2x_2 = y_2, …, xi−1=yi−1x_{i - 1} = y_{i - 1} 且 xi<yix_i \lt y_i 时,称 xx 的字典序小于 yy。

输入格式

The first line contains the integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Next 2t2t lines contain test cases — one per two lines.

The first line of each test case contains the integer nn (1≤n≤1051 \le n \le 10^5) — the length of the string ss.

The second line contains the binary string ss. The string ss is a string of length nn which consists only of zeroes and ones.

It's guaranteed that sum of nn over test cases doesn't exceed 10510^5.

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

接下来的 2t2t 行包含测试用例 —— 每两个行为一个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 表示字符串 ss 的长度。

每个测试用例的第二行包含一个二进制字符串 ss。字符串 ss 是一个长度为 nn 的字符串,仅由字符 0 和 1 组成。

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

输出格式

Print tt answers — one per test case.

The answer to the ii-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).

输出 tt 个答案——每个测试用例对应一个答案。

第 ii 个测试用例的答案是 Lee 在进行若干次(可能为零次)操作后所能得到的最“干净”的字符串。

输入输出样例

  • 输入#1

    5
    10
    0001111111
    4
    0101
    8
    11001101
    10
    1110000000
    1
    1

    输出#1

    0001111111
    001
    01
    0
    1

说明/提示

In the first test case, Lee can't perform any moves.

In the second test case, Lee should erase s2s_2.

In the third test case, Lee can make moves, for example, in the following order: 11001101 →\rightarrow 1100101 →\rightarrow 110101 →\rightarrow 10101 →\rightarrow 1101 →\rightarrow 101 →\rightarrow 01.

在第一个测试用例中,Lee 无法进行任何操作。

在第二个测试用例中,Lee 应当删除 s2s_2。

在第三个测试用例中,Lee 可以进行若干次操作,例如按如下顺序:11001101 →\rightarrow 1100101 →\rightarrow 110101 →\rightarrow 10101 →\rightarrow 1101 →\rightarrow 101 →\rightarrow 01。

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

首页