Ozon Tech Challenge 2020 B.Kuroni and Simple Strings

Ozon Tech Challenge 2020 B.Kuroni and Simple Strings

题目链接
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 n characters ‘(’ or ‘)’ is simple if its length n is even and positive, its first n2 characters are ‘(’, and its last n2 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 a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters.

Input

The only line of input contains a string s (1≤|s|≤1000) formed by characters ‘(’ and ‘)’, where |s| is the length of s.

Output

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

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

Then, print a line containing m integers 1≤a1

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

Examples

input

(()((

output

1
2
1 3 

input

)(

output

0

input

(()())

output

1
4
1 2 5 6 

这道题就简单模拟,首先如果一个字符串可以取最优解肯定是1次,可以自己举例想,用双指针跑一遍即可,AC代码如下:

#include
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin>>s;
    int l=0,r=s.size()-1;
    set<int>ans;
    while(l<r){
        while(l<s.size() && s[l]==')')
            l++;
        while(r>=0 && s[r]=='(')
            r--;
        if(l<s.size() && r>=0 && l<r)
            ans.insert(l+1),ans.insert(r+1),l++,r--;
    }
    if(ans.size()==0) puts("0");
    else{
        cout<<1<<endl<<ans.size()<<endl;
        for(set<int>::iterator i=ans.begin();i!=ans.end();i++)
            cout<<*i<<" ";
    }
    return 0;
}

你可能感兴趣的:(Codeforces,模拟,字符串)