Brackets Match Codeforces 5C

Source: Internet
Author: User

Description

This was yet another problem dealing with regular bracket sequences.

We should remind you a bracket sequence are called regular, if by inserting«+»and«1»into It we can get a C Orrect mathematical expression. For example, Sequences«(()) ()»,«()»and«(() (())»are Regular, while«) (»,«(()»and«(())) (»a Re not.

You are given a string of«(»and«)»characters. You were to find it longest substring that was a regular bracket sequence. You is 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 6.

Output

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

Sample Input

Input
)((())))(()())
Output
6 2
Input
))(
Output
0 1
#include <cstdio> #include <queue> #include <stack> #include <cmath> #include <cstring># Include <cstdlib> #include <iostream> #include <algorithm>using namespace std;typedef long LL; const int OO = 1e9;const double PI = ACOs ( -1); const int N = 1e6+7;char Str[n];int len[n];/**< If this position is ') ' save start from string header to this bit    The maximum number of matches */int main () {int I, ans=0, sum=0;    Stack <int >sta;    scanf ("%s", str);    int M = strlen (str);        for (i = 0; i < M; i++) {if (str[i] = = ' (') sta.push (i);            else if (sta.size ()) {int top = Sta.top ();            Sta.pop ();            if (str[top-1] = = ') ') len[i] = (i-top+1) + len[top-1];            else len[i] = (i-top+1);        ans = max (ans, len[i]); }} for (i = M-1; I >= 0; i--) {if (str[i] = = ') ' && len[i] && len[i] = = ans) sum    ++;    } if (sum = = 0) sum = 1;    printf ("%d%d\n", ans, sum); RetuRN 0;} 

  

Brackets Match Codeforces 5C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.