题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b?tpId=37&tqId=21293&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=3&judgeStatus=undefined&tags=&title=
n = int(input()) a = [0] * n b = [0] * n for i in range(n): a[i], b[i] = map(int, input().split(" ")) s = input() ans = 0 stack = [] for ch in s: if ch == ')': b1, b2 = stack.pop() a1, a2 = stack.pop() ans += a1 * a2 * b2 stack.append([a1, b2]) elif ch != '(': idx = ord(ch) - ord('A') stack.append([a[idx], b[idx]]) print(ans)