www codechef com dec14 problems chefbr

3
 pdfcrowd.com ope n in br owser PRO v ers ion Are you a developer? Try out the HTML to PDF API SUBMIT ALL SUBMISSIONS Read problems statements in Mandarin Chinese and Russian. Chef loves brackets. So much so, that rather than just use pla in brackets like (), {}, or [ ], he has invented his own no tation t hat allows him to use many more types of brack ets. Each type of bracket is designated by an integer. A negative integer -x represents an opening bracket of type x; while a p ositive integer x represents a closing bracket of t y pe x. Any sequence o f such integers is then called a bracket-pair sequence.  A balanced  bracket-pair sequence can be defined recursively as follows : The empty sequence is a balanced bracket-p air sequence. If S is a balanced bracket-pair sequence, the n -x S x is a balanced bracket-pair sequence for any positive integer x. If S and T are balanced bracket-pair sequences, then S T is a balanced bracket-pair sequence. For ex ample, "-1 -2 2 -3 -4 4 3 1" is a balanced bracket-pair sequen ce, but " -1 -2 1 2" is not. Chef has a bracket-pair sequence (which may or may not be balanced) consisting of N integers. There are 2 N  ways to form a subsequence of hi s sequence. He wants to know how many of these subsequences are balanced. Help him to calculate t his num ber, modulo 10 9 +7. Input The first line cont ains a s ingle integer N denoting the number of brack ets in his sequ ence. User Score Mem Lang Solution shuxxkk 10 0.000 0.3M PAS fpc View shivammadeshia 100.000 2.2M C View shreyans1995 100.000 2.3M C View leon_ken 100.000 2.3M C View Gurneet Singh 100.000 2.3M C View foraml 100. 000 2. 7M C+ + 4. 3. 2 View vytenis 100. 000 2. 7M C+ + 4 .3 .2 View karolis_kusas 100. 000 2. 7M C+ + 4 .3 .2 View ++ View SUCCESSFUL SUBMISSIONS Home » Compete » December Challenge 2014 » Che f and Bracket-Pairs Chef and Bracket-Pairs Problem code: CHEFBR Signup Login or Signup with Login Note 2 people like this. Sign Up to see w hat you r friends lik e. Like Shar e PRACTICE COM PETE DISCUSS HE LP ABOUT COMMUNITY

Upload: chantaiah

Post on 08-Oct-2015

71 views

Category:

Documents


0 download

DESCRIPTION

Problem

TRANSCRIPT

  • pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

    SUBMITALL SUBMISSIONS

    Read problems statements in Mandarin Chinese and Russian.

    Chef loves brackets. So much so, that rather than just use plain brackets like (), {}, or [], he has inventedhis own notation that allows him to use many more types of brackets.

    Each type of bracket is designated by an integer. A negative integer -x represents an opening bracket oftype x; while a positive integer x represents a closing bracket of type x. Any sequence of such integers isthen called a bracket-pair sequence.

    A balanced bracket-pair sequence can be defined recursively as follows:The empty sequence is a balanced bracket-pair sequence.

    If S is a balanced bracket-pair sequence, then -x S x is a balanced bracket-pair sequence for anypositive integer x.

    If S and T are balanced bracket-pair sequences, then S T is a balanced bracket-pair sequence.

    For example, "-1 -2 2 -3 -4 4 3 1" is a balanced bracket-pair sequence, but "-1 -2 1 2" is not.

    Chef has a bracket-pair sequence (which may or may not be balanced) consisting of N integers. There

    are 2N ways to form a subsequence of his sequence. He wants to know how many of thesesubsequences are balanced.

    Help him to calculate this number, modulo 109+7.

    Input

    The first line contains a single integer N denoting the number of brackets in his sequence.

    User Score Mem Lang Solution

    shuxxkk 100.000 0.3M PAS fpc View

    shivammadeshia 100.000 2.2M C View

    shreyans1995 100.000 2.3M C View

    leon_ken 100.000 2.3M C View

    Gurneet Singh 100.000 2.3M C View

    foraml 100.000 2.7M C++ 4.3.2 View

    vytenis 100.000 2.7M C++ 4.3.2 View

    karolis_kusas 100.000 2.7M C++ 4.3.2 View

    dejko95 100.000 2.7M C++ 4.3.2 View

    SUCCESSFUL SUBMISSIONS

    Home Compete December Challenge 2014 Chef and Bracket-Pairs

    Chef and Bracket-PairsProblem code: CHEFBR

    Signup Login orSignup with

    Login Note

    2 people like this. Sign Up to see w hat yourfriends like.

    Like Share

    PRACTICE COMPETE DISCUSS HELP ABOUTCOMMUNITY

  • pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

    Author: berezin

    Tags berezin

    Date Added: 20-03-2014

    Time Limit: 1 sec

    SourceLimit: 50000 Bytes

    Languages:

    ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.8.1, CPP11,CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl,LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH,PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC

    The second line contains N space-separated integers A1, A2, ..., AN denoting the types of brackets. A

    negative number means an opening bracket; a positive number means a closing bracket.

    Output

    In a single line print the required answer.

    Constraints

    1 N 100

    -109 Ai 109

    Ai 0

    It is not guaranteed that each opening bracket has a closing bracket of same type and vice-versa.

    Example

    Input:11-1 -2 9 2 -3 -4 3 4 8 8 1

    Output:12

    Comments

    dejko95 100.000 2.7M C++ 4.3.2 View

    fhlasek 100.000 2.7M C++ 4.3.2 View

    nblt 100.000 2.7M C++ 4.3.2 View

    mugurelionut 100.000 2.7M C++ 4.3.2 View

    Please login at the top to post a comment.

    1 of 16

  • pdfcrowd.comopen in browser PRO version Are you a developer? Try out the HTML to PDF API

    2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ by Sphere Research Labs

    About CodeChef About Directi CEO's Corner C-Programming Programming Languages Contact Us

    In order to report copyright violations of any kind, send in an email to [email protected]

    CodeChef is a non-commercial competitive programming community

    CodeChef - A Platform for Aspiring Programmers

    CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard torevive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to havetraining sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions,CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

    Practice Section - A Place to hone your 'Computer Programming Skills'

    Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to betterprepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

    Compete - Monthly Programming Contests and Cook-offs

    Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourselfup for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

    Discuss

    Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out otherprogrammers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting theCodeChef Forums and Wiki section.

    CodeChef Community

    As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is notthe only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

    Go For Gold

    The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to theACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive theGo for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPCcompetition here.

    The time now is: 01:43:43 PM Your Ip: 69.164.218.62