-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2504.py
51 lines (43 loc) · 1012 Bytes
/
2504.py
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
# 괄호의 값
import sys
input = sys.stdin.readline
S = input().rstrip()
correct = True
stack = []
for i in S:
if i == "(" or i == "[":
stack.append(i)
else:
cnt = 0
if stack:
last = stack.pop()
else:
correct = False
break
while True:
if type(last) == int:
cnt += last
if stack:
last = stack.pop()
else:
correct = False
break
else:
cnt = max(1, cnt)
if last == "(" and i == ")":
stack.append(cnt * 2)
elif last == "[" and i == "]":
stack.append(cnt * 3)
else:
correct = False
break
if not correct:
break
for i in stack:
if type(i) == str:
correct = False
break
if correct:
print(sum(stack))
else:
print(0)