-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOJ15926.cpp
74 lines (63 loc) · 1.18 KB
/
BOJ15926.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
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
int N;
string input;
int nlist[200200];
stack<int> s;
int main()
{
scanf("%d", &N);
cin >> input;
for (int i = 0; i < N;++i) {
if (input[i] == '(') {
s.push(i);
}
else {
if (!s.empty()) {
nlist[i] = 1;
nlist[s.top()] = 1;
s.pop();
}
}
}
int cnt = 0;
int ans = 0;
for (int i = 0; i < N; ++i) {
if (nlist[i] == 1) {
++cnt;
ans = max(ans, cnt);
}
else {
cnt = 0;
}
}
printf("%d", ans);
return 0;
}
/*
//csehydrogen's solution
#include <cstdio>
#include <algorithm>
char a[200001];
int s[200001], st;
int main() {
int n, ans = 0;
scanf("%d%s", &n, a);
s[st++] = -1;
for (int i = 0; i < n; ++i) {
if (a[i] == '(') {
s[st++] = i;
} else {
--st;
if (st == 0) {
s[st++] = i;
} else {
ans = std::max(ans, i - s[st - 1]);
}
}
}
printf("%d\n", ans);
return 0;
}
*/