hihoCoder Challenge 20 register

Ended

Participants:577

Verdict:Accepted
Submitted:2016-05-06 19:22:35

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define ll long long
using namespace std;
char str[1000006];
int len,dat[100006],tot;
int main(){
    scanf("%s",str+1);
    len=strlen(str+1);
    int cnt=0;
    ll ans=0;;
    for(int i=1;i<=len;i++){
        if(str[i]=='(')dat[++cnt]=0;
        if(str[i]==')'){
            --cnt;
            if(cnt<0)dat[cnt=0]=0;  
            else{
                dat[cnt]++;
                ans+=dat[cnt];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX