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. mysql 聚集函数 count 使用详解

    mysql 聚集函数 count 使用详解 本文将探讨以下问题 1.count(*) . count(n).count(null)与count(fieldName) 2.distinct 与 coun ...

  2. Hadoop(十一):组合任务概述和格式

    组合任务概述 一些复杂的任务很难由一个MR处理完成,所以一般需要将其拆分成为多个简单的MR子任务来执行. MapReduce框架中对于这类的问题提供了几种方式进行任务执行流程的控制,主要包括以下几种方 ...

  3. spring07

    关于spring的泛型依赖注入主要是继承等方面的知识 具体实现的简单的代码如下: package bao1; public class BaseRepository <T>{ } pack ...

  4. MTK Android 设置下添加一级菜单[ZedielPcbTest]

    功能描述:Android7.1.2 设置下添加一级菜单[ZedielPcbTest],点击ZedielPcbTest,启动ZedielPcbTest.apk应用. 编译:需要在out目录删除Settt ...

  5. node+express+mysql实现简单的数据增删改查

    前提 电脑已经安装了node,express,mysql. 实现步骤 1.新建数据库表 附数据表结构: 2.创建exprss项目 express -e myapp  新建一个以ejs为模板的expre ...

  6. Docker+Jmeter+InfluxDB+Grafana搭建性能测试监控平台

    搭建需求? jmeter自身的聚合测试报告可视化效果极差,为更加形象的.动态的展示测试过程,需要一个具有时序性的可视区来展示给我们的测试者, 这时候就需要用到后端监控,下面我们来开始搭建符合这种测试需 ...

  7. C语言实现链表(链式存储结构)

    链表(链式存储结构)及创建 链表,别名链式存储结构或单链表,用于存储逻辑关系为 "一对一" 的数据.与顺序表不同,链表不限制数据的物理存储状态,换句话说,使用链表存储的数据元素,其 ...

  8. 史上最详细mac安装Qt教程

    史上最详细mac安装Qt教程,小白看过来! 这是一篇非常适合Qt入门小白的的安装Qt教程,因为这学期我们小组的一个关于高速救援的项目要用到Qt与web进行交互式展现相关的图像,由于没有MSVC这个插件 ...

  9. tf.nn.bias_add 激活函数

    tf.nn.bias_add(value,bias,data_format=None,name=None) 参数: value:一个Tensor,类型为float,double,int64,int32 ...

  10. AJ学IOS(47)之网易彩票帮助界面UIWebView的运用

    AJ分享,必须精品 效果: 制作过程 首先是帮助按钮那个地方的点击. 这里是用点击跳转的用的是 NJSettingArrowItem,前面的设置的,从字典通过模型转过来的. // 分享 NJSetti ...