This is yet another problem dealing with regular bracket sequences.

We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.

You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.

Input

The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.

Output

Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".

Examples

Input
)((())))(()())
Output
6 2
Input
))(
Output
0 1
题解:DP。用栈存每一个‘(’的下标,遇到一个')',判断一下栈是否为空,若为空,则继续往后,若不为空,则新增加长度为:i-temp+1;
参考代码为:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
char s[maxn];
int dp[maxn];
int main()
{
scanf("%s",s+1); stack<int> st;
int len=strlen(s+1),Max=1,ans=0;
for(int i=1;i<=len;i++)
{
if(s[i]=='(') st.push(i);
else
{
if(!st.empty())
{
int temp=st.top(); st.pop();
dp[i]=dp[temp-1]+i-temp+1;
Max=max(dp[i],Max);
}
}
}
if(Max==1) printf("0 1\n");
else
{
for(int i=1;i<=len;i++) if(dp[i]==Max) ans++;
printf("%d %d\n",Max,ans);
}
return 0;
}

  

CodeForces 5C Longest Regular Backet sequence的更多相关文章

  1. Codeforces 5C Longest Regular Bracket Sequence(DP+括号匹配)

    题目链接:http://codeforces.com/problemset/problem/5/C 题目大意:给出一串字符串只有'('和')',求出符合括号匹配规则的最大字串长度及该长度的字串出现的次 ...

  2. (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)

    (CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...

  3. Codeforces Beta Round #5 C. Longest Regular Bracket Sequence 栈/dp

    C. Longest Regular Bracket Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...

  4. 贪心+stack Codeforces Beta Round #5 C. Longest Regular Bracket Sequence

    题目传送门 /* 题意:求最长括号匹配的长度和它的个数 贪心+stack:用栈存放最近的左括号的位置,若是有右括号匹配,则记录它们的长度,更新最大值,可以在O (n)解决 详细解释:http://bl ...

  5. 【Codeforces】CF 5 C Longest Regular Bracket Sequence(dp)

    题目 传送门:QWQ 分析 洛谷题解里有一位大佬讲的很好. 就是先用栈预处理出可以匹配的左右括号在数组中设为1 其他为0 最后求一下最长连续1的数量. 代码 #include <bits/std ...

  6. codeforces 5C

    C. Longest Regular Bracket Sequence time limit per test 2 seconds memory limit per test 256 megabyte ...

  7. Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence 栈

    C. Replace To Make Regular Bracket Sequence 题目连接: http://www.codeforces.com/contest/612/problem/C De ...

  8. Almost Regular Bracket Sequence CodeForces - 1095E (线段树,单点更新,区间查询维护括号序列)

    Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of ...

  9. CodeForces - 612C Replace To Make Regular Bracket Sequence 压栈

    C. Replace To Make Regular Bracket Sequence time limit per test 1 second memory limit per test 256 m ...

随机推荐

  1. python中字符串常见操作(二)

    # 可迭代对象有:字典,列表,元组,字符串,集合 str1 = '192.168.1.1' str2 = 'as df gh jk' str3 = '小李子' str4 = ['aa','bb','c ...

  2. 利用JaCoCo统计接口测试中代码覆盖率

    ​        做接口测试,很多时候都会听到,你接口测试的覆盖率是多少?很多人会回答80%,你怎么统计的,他说覆盖了80%的需求.这个回答没有错误,但是片面,我们不能只考虑需求的覆盖率,还有业务的覆 ...

  3. Java 读取Word批注中的文本和图片

    本文将介绍读取Word批注的方法,包括读取Word批注中的文本及图片.关于操作Word批注的方法还可以参考这两篇文章:Java 添加.回复.修改.删除Word批注:Java 给Word指定字符串添加批 ...

  4. scipy.sparse的csc_matrix、csr_matrix与coo_matrix区别与应用(思维导图)

  5. usaco training <1.2 Greedy Gift Givers>

    题面 Task 'gift1': Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided t ...

  6. echarts绘制彩虹色背景

    大致成品如图所示 关键的步骤: var dom = document.getElementById("myChart"); var myChart = echarts.init(d ...

  7. go中的关键字-go(下)

    1. goroutine源码分析 1.1 初始化 go程序的启动流程分为四步 call osinit, 这里就是设置了全局变量ncpu = cpu核心数量 call schedinit make &a ...

  8. pycham永久激活及conda环境部署

    1.pycham安装 一般不选择最新版本,我用的是2018.3,选择 Professional专业版 1.1 官网地址: https://www.jetbrains.com/pycharm/downl ...

  9. HTTPS 原理分析——带着疑问层层深入

    HTTPS 随着 HTTPS 建站的成本下降,现在大部分的网站都已经开始用上 HTTPS 协议.大家都知道 HTTPS 比 HTTP 安全,也听说过与 HTTPS 协议相关的概念有 SSL .非对称加 ...

  10. Golang 指针理解

    目录 0x00 指针地址和指针类型 0x01 从指针获取指针指向的值 0x02 使用指针修改值 0x03 返回函数中局部变量 0x04 使用 new() 创建指针 0x05 flag包的指针技术 0x ...