-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path24552.cpp
81 lines (69 loc) · 1.37 KB
/
24552.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <string>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <set>
#define p(a, b) make_pair(a, b)
#define SWAP(a, b, type) do { \
type temp; \
temp = a; \
a = b; \
b = temp; \
} while (0)
#define INF 1000000000
#define endl '\n'
#define ll long long
using namespace std;
int sum1[1000001];
int sum2[1000001];
string s;
void input() {
cin>>s;
}
void init() {
}
void solution() {
int cnt1 = 0, cnt2=0;
for(int i=0;i<s.size();i++){
if(s[i]=='(') cnt1++;
else cnt2++;
}
if(cnt1<cnt2){
for(int i=0;i<s.size();i++){
if(i!=0){
sum1[i]= sum1[i-1];
sum2[i] = sum2[i-1];
}
if(s[i]=='(') sum1[i]++;
else sum2[i]++;
}
}else{
for(int i=0;i<s.size();i++){
if(i!=0){
sum1[i]= sum1[i-1];
sum2[i] = sum2[i-1];
}
if(s[s.size()-1-i]==')') sum1[i]++;
else sum2[i]++;
}
}
for(int i=0;i<s.size();i++){
if(sum1[i]+1==sum2[i]){
cout<<sum2[i];
return;
}
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
input();
solution();
return 0;
}