Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#define N 1000005#define ll long longusing namespace std;const int INF = 111111;char str[N];ll a[N], b[N];int main(){#ifndef ONLINE_JUDGEfreopen("1.txt", "r", stdin);#endifll 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];}}