hihoCoder Challenge 20 register

Ended

Participants:577

Verdict:Accepted
Submitted:2016-05-06 19:29:02

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
28
29
30
31
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define N 1000005
#define ll long long
using namespace std;
const int INF = 111111;
char str[N];
ll a[N], b[N];
int main(){
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif
    ll i, j, T, k, l, t, h;
    ll  ans;
    while(~scanf("%s", str)){
        l = strlen(str);
        ans = 0;
        for (i = 1; i < l; i++){
            if (str[i] == ')'){
                j = i-a[i-1]-1;
                if (j >= 0 && str[j] == '('){
                    a[i] = a[i-1]+2;
                    b[i] = 1;
                    if (j > 0){
                        b[i] += b[j-1];
                        a[i] += a[j-1];
                    }
                }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX