-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
47 lines (39 loc) · 942 Bytes
/
C.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
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
void run_cases() {
string s;
cin >> s;
int n = s.length();
vector<int> cnt(n + 1);
vector<pair<char, int>> st;
st.push_back({'#', -1});
for(int i = 0; i < n; i++) {
if(s[i] == '(') {
st.emplace_back(s[i], i);
} else {
if(st.back().first == '(') {
int top = st.back().second;
st.pop_back();
cnt[i - st.back().second]++;
} else {
st.emplace_back(')', i);
}
}
}
for(int i = n; i >= 0; i--) {
if(cnt[i] > 0) {
cout << i << " " << cnt[i] << '\n';
return;
}
}
cout << "0 1";
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr);
int tests = 1;
// cin >> tests;
for(int test = 1;test <= tests;test++) {
run_cases();
}
}