• B. Kuroni and Simple Strings


    B. Kuroni and Simple Strings

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    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 n2n2 characters are '(', and its last n2n2 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.

    Input

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

    Output

    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

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

    Examples

    input

    Copy

    (()((
    

    output

    Copy

    1
    2
    1 3 
    

    input

    Copy

    )(
    

    output

    Copy

    0
    

    input

    Copy

    (()())
    

    output

    Copy

    1
    4
    1 2 5 6 
    

    Note

    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.

    =========================================================================

    从两端开始匹配是最优的,并且不会在一次完整遍历之后还留下能够配对的,剩下的都是无法进行配对的

    1. # include
    2. # include
    3. # include
    4. # include
    5. using namespace std;
    6. vector<int>v;
    7. int main ()
    8. {
    9. string s;
    10. cin>>s;
    11. s=" "+s;
    12. int left=1,right=s.length()-1;
    13. while(left
    14. {
    15. if(s[left]=='('&&s[right]==')')
    16. {
    17. v.push_back(left);
    18. v.push_back(right);
    19. left++;
    20. right--;
    21. }
    22. else if(s[left]==')')
    23. left++;
    24. else if(s[right]=='(')
    25. right--;
    26. }
    27. if(v.size())
    28. {
    29. cout<<1<
    30. cout<size()<
    31. sort(v.begin(),v.end());
    32. for(auto it:v)
    33. {
    34. cout<" ";
    35. }
    36. }
    37. else
    38. {
    39. cout<<0;
    40. }
    41. return 0;
    42. }

  • 相关阅读:
    Mac电脑idea中配置nodejs前端环境
    SpringBoot 实战 开发中 16 条最佳实践
    六级易混词整理
    php8.1-common : 依赖: libffi6 (>= 3.2) 但无法安装它(树莓派4B kali)
    使用 Docker 自建一款怀旧游戏之 - 扫雷
    35m预应力简支梁桥毕业设计 课程设计-桥梁工程(计算书、8张CAD图)
    二叉树路径问题+递归+有关题目
    CSS_实现三角形和聊天气泡框
    机器学习之回归
    Nuxt3环境变量配置
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126302330