22714_BestParenthesis

2022-5-16 18:22| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506884767500-Problem List-采集的数据-后羿采集器.html

Pro.ID

22714

Title

Best Parenthesis

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22714

AC

2

Submit

77

Ratio

2.60%

时间&空间限制

  • Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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.

    输入

    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 ')'

    输出

    Description

    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.

    Input

    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 ')'

    Output
    Line 1: The score of the string. Since this number can get quite large, output the  score modulo 12345678910.
    Sample Input

    6
    0
    0
    1
    1
    0
    1


    This corresponds to the string "(())()".

    Sample Output

    3


    As discussed above.

    Source

    样例输入

    6
    0
    0
    1
    1
    0
    1


    This corresponds to the string "(())()".

    样例输出

    3


    As discussed above.

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部