CF2233C.Cost of a Bracket Sequence

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Let the cost of an arbitrary bracket string be the length of it's longest subsequence∗^{\text{∗}} that is a regular bracket sequence†^{\text{†}}.

You are given a bracket string ss and an integer kk. Your task is to remove at most kk characters from the string ss so that the cost of the resulting string is minimized.

∗^{\text{∗}}A sequence aa is a subsequence of a sequence bb if aa can be obtained from bb by the deletion of several (possibly, zero or all) element from arbitrary positions.

†^{\text{†}}A bracket sequence is called regular if it is possible to obtain a correct arithmetic expression by inserting the characters ++ and 11 into this sequence. For example, the sequences "(())()\texttt{(())()}", "()\texttt{()}", and "(()(()))\texttt{(()(()))}" are regular, while ")(\texttt{)(}", "(()\texttt{(()}", and "(()))(\texttt{(()))(}" — are not.

定义任意括号串的代价为:其最长子序列(∗^{\text{∗}})的长度,该子序列本身是一个合法括号序列(†^{\text{†}})。

给定一个括号串 ss 和一个整数 kk。你的任务是从字符串 ss 中最多删除 kk 个字符,使得所得字符串的代价最小化。

∗^{\text{∗}} 序列 aa 是序列 bb 的子序列,当且仅当 aa 可通过从 bb 中任意位置删除若干个(可能为零个或全部)元素而得到。

†^{\text{†}} 若能在该括号序列中插入字符 ++ 和 11,从而得到一个合法的算术表达式,则称该括号序列是合法的。例如,串 "(())()\texttt{(())()}"、"()\texttt{()}" 和 "(()(()))\texttt{(()(()))}" 是合法的;而 ")(\texttt{)(}"、"(()\texttt{(()}" 和 "(()))(\texttt{(()))(}" 则不是。

输入格式

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

The first line of each test case contains two integers nn and kk (1≤n≤5 0001 \le n \le 5\,000; 0≤k≤n0 \le k \le n) — the length of the string ss and the maximum number of deletions.

The second line of each test case contains a string ss of length nn consisting of the characters "(\texttt{(}" and/or ")\texttt{)}".

Additional input constraints:

  • the sum of nn over all test cases does not exceed 5 0005\,000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1031 \le t \le 10^3)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤5 0001 \le n \le 5\,000;0≤k≤n0 \le k \le n)——分别表示字符串 ss 的长度以及最多允许的删除次数。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss,其仅由字符 "(\texttt{(}" 和/或 ")\texttt{)}" 组成。

附加输入约束:

  • 所有测试用例的 nn 值之和不超过 5 0005\,000。

输出格式

For each test case, output a binary string of length nn. The ii-th character should be equal to "1" if the corresponding character of the string ss is removed, and "0" otherwise.

The number of ones in the string must not exceed kk. The cost of the string obtained after removing the marked characters must be as small as possible.

If there are several answers, output any of them.

对于每个测试用例,输出一个长度为 nn 的二进制字符串。其中第 ii 个字符应为 "1",当且仅当字符串 ss 中对应位置的字符被删除;否则为 "0"。

该二进制字符串中 "1" 的个数不得超过 kk。在删除被标记为 "1" 的字符后所得字符串的代价须尽可能小。

若存在多个满足条件的答案,输出任意一个即可。

输入输出样例

  • 输入#1

    10
    2 1
    )(
    2 0
    ()
    4 1
    (())
    4 1
    ())(
    5 1
    ((())
    6 2
    ()()()
    6 2
    (()())
    6 2
    ())(()
    7 3
    (()((()
    10 3
    (()())())(

    输出#1

    00
    00
    1000
    1000
    00010
    101000
    001001
    100001
    1100001
    0101001000

说明/提示

In the first test case, the cost of the string is already 00, so it is possible not to delete anything.

In the third test case, it is impossible to obtain a string of cost 00 after one deletion, but it is possible to obtain a string of cost 22 by deleting any character.

在第一个测试用例中,字符串的代价已经是 00,因此可以不删除任何字符。

在第三个测试用例中,经过一次删除操作后无法得到代价为 00 的字符串,但通过删除任意一个字符,可以得到代价为 22 的字符串。

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

首页