B. Kuroni and Simple Strings

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard 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 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<a2<⋯<am — 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 k, you may print any of them.

Examples

inputCopy

(()((

outputCopy

1

2

1 3

inputCopy

)(

outputCopy

0

inputCopy

(()())

outputCopy

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 2 and 3, which results in the same final string.

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

把所有左右能匹配的都去掉,剩下的一定不能匹配。

#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
} #define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
vector<int> Q;
int main()
{
string s;
cin >> s;
int n = s.size();
int l = 0, r = n - 1;
while (l < r)
{
while (l < n && s[l] != '(')
l++;
while (r >= 0 && s[r] != ')')
r--;
if (r <= l)
break;
else
{
Q.push_back(l + 1);
Q.push_back(r + 1);
}
l++, r--;
}
if (Q.size() == 0)
{
puts("0");
return 0;
}
sort(Q.begin(), Q.end()); puts("1");
wi(Q.size()), P;
for (auto a : Q)
wi(a);
}

Codeforce-Ozon Tech Challenge 2020-B. Kuroni and Simple Strings(贪心)的更多相关文章

  1. Codeforce-Ozon Tech Challenge 2020-D. Kuroni and the Celebration(交互题+DFS)

    After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem, Kuroni went to an Ital ...

  2. Codeforce-Ozon Tech Challenge 2020-C. Kuroni and Impossible Calculation(鸽笼原理)

    To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a ...

  3. Codeforce-Ozon Tech Challenge 2020-A. Kuroni and the Gifts

    the i-th necklace has a brightness ai, where all the ai are pairwise distinct (i.e. all ai are diffe ...

  4. codeforce AIM tech Round 4 div 2 B rectangles

    2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...

  5. Codechef May Challenge 2020 Division 1 记录

    目录 Triple Sort Sorting Vases Buying a New String Chef and Bitwise Product Binary Land Not a Real Wor ...

  6. Codechef July Challenge 2020 Division 1 记录

    目录 Missing a Point Chefina and Swaps Doctor Chef Chef and Dragon Dens LCM Constraints Weird Product ...

  7. Codechef June Challenge 2020 Division 1 记录

    目录 The Tom and Jerry Game! Operations on a Tuple The Delicious Cake Convenient Airports Guessing Gam ...

  8. AIM Tech Round (Div. 2) B. Making a String 贪心

    B. Making a String 题目连接: http://codeforces.com/contest/624/problem/B Description You are given an al ...

  9. codeforce Gym 100685E Epic Fail of a Genie(MaximumProduction 贪心)

    题意:给出一堆元素,求一个子集,使子集的乘积最大,如有多个,应该使子集元素个数尽量小. 题解:贪心,如果有大于1的正数,那么是一定要选的,注意负数也可能凑出大于1的正数,那么将绝对值大于1的负数两两配 ...

随机推荐

  1. kali2016&2019的安装使用

    先解释一下,为什么要说2016&2019哪,这是因为有一些测试靶机环境在2016以上的系统安装不通过,所以有时候会特意找2016的镜像来用. 一.下载镜像 1.下载镜像当然要到官方去下载了: ...

  2. 家庭版记账本app开发进度。开发到现在整个app只剩下关于图表的设计了,具体功能如下

    首先说一下自己的功能: 实现了用户的登录和注册.添加收入记账和添加支出记账.粗略显示每条账单基本情况.通过点击每条账单来显示具体的情况, 之后就是退出当前用户的操作. 具体的页面情况如下: 这就是整个 ...

  3. python3(三十二) try except

    """ 异常处理 """ __author__on__ = 'shaozhiqi 2019/9/19' # 大量的代码来判断是否出错: # ...

  4. 将class 编译后文件内容输入到 文本文件中的命令

    javap -c InnerTest$1 > InnerTest$1.txt

  5. 【Java】Operator 运算符/操作符

    Operator 运算符/操作符 什么是操作符? 一个表示特定的数学或逻辑操作的符号 算术运算符 加 + 减 - 乘 * 除 / 取模 % 前置自运算 ++ a .--b 后置自运算 a++ .b-- ...

  6. 你知道如何自动保存 Spring Boot 应用进程号吗

    1. 前言 欢迎阅读 Spring Boot 2 实战 系列文章. PID 对于系统运维来说并不陌生,但是对于一些开发者特别是新手还是要简单介绍一下的.它是 Process ID 的简称,是系统分配给 ...

  7. 手把手教Extjs-简单GridField示例讲解二

    使用的Extjs版本为4.2,示例是官方的版本,对里面的语法进行一句一句的学习研究.可以方便他人,又可以提升自己的理解.里面存在的问题,后期会一步一步改进.也欢迎各位指出. /* Extjs具有很庞大 ...

  8. 哈密顿绕行世界问题 HDU2181

    题目大意都比较简单,用vector存一下图,然后爆搜就可以了. #include<bits/stdc++.h> using namespace std; ; vector<]; bo ...

  9. 44道JavaScript送命题

    很久以前看过一个老外写的帖子,JavaScript Puzzlers!,直译就是JavaScript难题,里面列举了100道JavaScript选择题,大部分都是让人摸不着头脑的题目,需要仔细琢磨一番 ...

  10. java Int类型转为double 类型;string转double

    int a=12; double b=(double)a; or double c=Double.valueOf((double)a); string a_s="12"; doub ...