forked from EndlessCheng/codeforces-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5C.go
61 lines (56 loc) · 852 Bytes
/
5C.go
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
package main
import (
"bufio"
. "fmt"
"io"
"strings"
)
// github.com/EndlessCheng/codeforces-go
func Sol5C(reader io.Reader, writer io.Writer) {
in := bufio.NewReader(reader)
out := bufio.NewWriter(writer)
defer out.Flush()
var s string
Fscan(in, &s)
bs := []byte(s)
size := 0
for i, c := range s {
if c == '(' {
size++
} else {
size--
if size < 0 {
bs[i] = ' '
size = 0
}
}
}
size = 0
for i := len(s) - 1; i >= 0; i-- {
if s[i] == ')' {
size++
} else {
size--
if size < 0 {
bs[i] = ' '
size = 0
}
}
}
maxLen := map[int]int{0: 1}
for _, ss := range strings.Split(string(bs), " ") {
if ss != "" {
maxLen[len(ss)]++
}
}
ans := 0
for l := range maxLen {
if l > ans {
ans = l
}
}
Fprint(out, ans, maxLen[ans])
}
//func main() {
// Sol5C(os.Stdin, os.Stdout)
//}