CF1305B.Kuroni and Simple Strings

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!

We say that a string formed by nn characters '(' or ')' is simple if its length nn is even and positive, its first n2\frac{n}{2} characters are '(', and its last n2\frac{n}{2} characters are ')'. For example, the strings () and (()) are simple, while the strings )( and ()() are not simple.

Kuroni will be given a string formed by characters '(' and ')' (the given string is not necessarily simple). An operation consists of choosing a subsequence of the characters of the string that forms a simple string and removing all the characters of this subsequence from the string. Note that this subsequence doesn't have to be continuous. For example, he can apply the operation to the string ')()(()))', to choose a subsequence of bold characters, as it forms a simple string '(())', delete these bold characters from the string and to get '))()'.

Kuroni has to perform the minimum possible number of operations on the string, in such a way that no more operations can be performed on the remaining string. The resulting string does not have to be empty.

Since the given string is too large, Kuroni is unable to figure out how to minimize the number of operations. Can you help him do it instead?

A sequence of characters aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters.

既然库罗尼已经10岁了,他已经成为一个小大人,不再喜欢整数数组作为生日礼物。今年,他想要一个括号序列作为生日礼物。更具体地说,他想要一个极其复杂的括号序列——无论他多么努力尝试,都无法从中移除任何一个“简单子序列”!

我们称一个由 nn 个字符 '(' 或 ')' 构成的字符串为简单字符串,当且仅当其长度 nn 是正偶数,且前 n2\frac{n}{2} 个字符全为 '(',后 n2\frac{n}{2} 个字符全为 ')'。例如,字符串 () 和 (()) 是简单字符串,而 )( 和 ()() 则不是。

库罗尼将获得一个仅由字符 '(' 和 ')' 组成的字符串(该字符串不一定是简单字符串)。一次操作定义为:选出原字符串的一个子序列,使得该子序列构成一个简单字符串,并将该子序列中的所有字符从原字符串中全部删除。注意:该子序列不必连续。例如,对字符串 ')()(()))',他可以选择加粗的字符构成简单字符串 '(())',然后将这些加粗字符从原字符串中删除,得到 '))()'。

库罗尼需要在给定字符串上执行尽可能少的操作次数,使得剩余字符串中再也无法执行任何操作(即不存在任何简单子序列可被移除)。最终剩余的字符串不一定为空。

由于给定字符串规模过大,库罗尼自己无法找出最小操作次数。你能帮他解决这个问题吗?

若字符串 bb 删除若干(可能为零或全部)字符后可得到字符序列 aa,则称 aa 是 bb 的一个子序列。

输入格式

The only line of input contains a string ss (1≤∣s∣≤10001 \le |s| \le 1000) formed by characters '(' and ')', where ∣s∣|s| is the length of ss.

输入仅包含一行,为一个由字符 '(' 和 ')' 构成的字符串 ss(1≤∣s∣≤10001 \le |s| \le 1000),其中 ∣s∣|s| 表示字符串 ss 的长度。

输出格式

In the first line, print an integer kk — the minimum number of operations you have to apply. Then, print 2k2k lines describing the operations in the following format:

For each operation, print a line containing an integer mm — the number of characters in the subsequence you will remove.

Then, print a line containing mm integers 1≤a1<a2<⋯<am1 \le a_1 \lt a_2 \lt \dots \lt a_m — the indices of the characters you will remove. All integers must be less than or equal to the length of the current string, and the corresponding subsequence must form a simple string.

If there are multiple valid sequences of operations with the smallest kk, you may print any of them.

第一行输出一个整数 kk —— 你需要执行的最少操作次数。随后,输出 2k2k 行,按如下格式描述这些操作:

对每次操作,先输出一行包含一个整数 mm —— 你将要删除的子序列的字符个数。

接着,再输出一行包含 mm 个整数 1≤a1<a2<⋯<am1 \le a_1 \lt a_2 \lt \dots \lt a_m —— 你将要删除的字符在当前字符串中的下标(从 1 开始计数)。所有整数必须不超过当前字符串的长度,且所对应的子序列必须构成一个简单字符串(simple string)。

若存在多个具有最小 kk 的合法操作序列,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    (()((

    输出#1

    1
    2
    1 3
  • 输入#2

    )(

    输出#2

    0
  • 输入#3

    (()())

    输出#3

    1
    4
    1 2 5 6

说明/提示

In the first sample, the string is '(()(('. The operation described corresponds to deleting the bolded subsequence. The resulting string is '(((', and no more operations can be performed on it. Another valid answer is choosing indices 22 and 33, which results in the same final string.

In the second sample, it is already impossible to perform any operations.

在第一个样例中,字符串为 '(()(('. 所描述的操作对应于删除加粗的子序列。得到的结果字符串为 '(((', 且无法再对其执行任何操作。另一个合法的答案是选择下标 22 和 33,这将得到相同的最终字符串。

在第二个样例中,已经无法执行任何操作。

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

首页