0% found this document useful (0 votes)
53 views1 page

Brackets

This document defines correct strings of brackets and broken strings of brackets. The task is to calculate the number of possible correct strings of brackets that could produce a given broken string of brackets. The input will be an even integer N representing the length of the broken string, and the broken string itself consisting of '(' and ')'. The output should be the number of possible correct strings modulo 1,000,000,009. Examples and test case details are provided.

Uploaded by

Shikhin Sethi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views1 page

Brackets

This document defines correct strings of brackets and broken strings of brackets. The task is to calculate the number of possible correct strings of brackets that could produce a given broken string of brackets. The input will be an even integer N representing the length of the broken string, and the broken string itself consisting of '(' and ')'. The output should be the number of possible correct strings modulo 1,000,000,009. Examples and test case details are provided.

Uploaded by

Shikhin Sethi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Day 1

BRACKETS

ENG

Task

Language

Brackets
Lets define a correct string of brackets as follows:
- () and [] are correct strings of brackets;
- if A is a correct string of brackets, then (A) and [A] are also correct strings of
brackets;
- if A and B are both correct strings of brackets, then the concatenation AB is also
a correct string of brackets;
In a correct string of brackets which contains at least one pair of square brackets:
[ and corresponding ], each square bracket (both opening and closing) was replaced
by the opening round bracket, therefore obtaining a broken string of brackets.
For example, (( and ((((())) both are broken strings of brackets. First string
is obtained from the correct strings of brackets []. Second string may be obtained
only
from
the
following
four
correct
strings
of
brackets:
[]((())),([](())),(([]())) or ((([]))).
Your task is for a given broken string of brackets calculate the number of possible
correct strings of brackets from which the given broken string may have been
obtained.
Input data
The first line of text file brackets.in contains a single even integer N (2N30000) the length of the given broken string of brackets. The second line contains N
characters ( and ) - the given broken string of brackets.
Output data
The single line of the text file brackets.out should contain one integer - the
required number of correct strings of brackets. Because the number of correct
strings of brackets can be large, you should output the answer modulo 1 000 000 009.
Examples
Input data
(file brackets.in)
4
((()

Output data
(file brackets.out)
2

Corresponding correct strings of brackets

Input data
(file brackets.in)
8
((((((((

Output data
(file brackets.out)
14

Corresponding correct strings of brackets

[](), ([])

[][][][], [[]][][], [[]][[]], [][][[]], [[[]]][], [[][]][],


[][[][]], [][[[]]], [[[[]]]], [[][[]]], [[[]][]], [[][][]],
[[[][]]], [][[]][]

Grading
Test cases where N50 are worth 20 points.
Test cases where N1000 are worth 45 points.

Page 1 of 1

You might also like