#P3015. [USACO11FEB] Best Parenthesis S
[USACO11FEB] Best Parenthesis S
题目描述
Recently, the cows have been competing with strings of balanced parentheses and comparing them with each other to see who has the best one.
Such strings are scored as follows (all strings are balanced): the string '()' has score 1; if 'A' has score s(A) then '(A)' has score 2*s(A); and if 'A' and 'B' have scores s(A) and s(B), respectively, then 'AB' has score s(A)+s(B). For example, s('(())()') = s('(())')+s('()') = 2*s('()')+1 = 2*1+1 = 3.
Bessie wants to beat all of her fellow cows, so she needs to calculate the score of some strings. Given a string of balanced parentheses of length N (2 <= N <= 100,000), help Bessie compute its score.
给定一个只包含左右括号的字符串,得分规则如下:
如果一对括号内没有括号,那么这对括号的得分为1;如果两对括号互不包含(即并列存在),那这两对括号的得分相加;如果括号内包含一对括号,那么这个括号的得分纪为内部括号序列的得分*2。
例如:对于这样一个字符串:"() ()",两对括号并列存在,则得分为1+1=2;
而对于这样一个字符串:"(())",最外层的括号内层包含一对括号,则得分为2*1=2.
Bessie想击败所有同事的牛,所以她需要计算某个字符串的评分。给定一个长度为n、只包含括号的字符串(2≤N≤100000),计算其得分帮助Bessie。
输入格式
* Line 1: A single integer: N
* Lines 2..N + 1: Line i+1 will contain 1 integer: 0 if the ith character of the string is '(', and 1 if the ith character of the string is ')'
输出格式
* Line 1: The score of the string. Since this number can get quite large, output the score modulo 12345678910.
6
0
0
1
1
0
1
3
提示
This corresponds to the string "(())()".
As discussed above.
输出答案要mod12345678910