codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

770D.md (2526B)


      1 Source: https://codeforces.com/problemset/problem/770/D
      2 
      3 D. Draw Brackets!
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[]]][" — are irregular.
     22 
     23 Draw the given sequence using a minimalistic pseudographics in the strip of the lowest possible height — use symbols '+', '-' and '|'. For example, the sequence "[[][]][]" should be represented as:
     24 
     25 ```
     26 +-        -++- -+      
     27 |+- -++- -+||   |  
     28 ||   ||   |||   |  
     29 |+- -++- -+||   |  
     30 +-        -++- -+
     31 ```
     32 
     33 Each bracket should be represented with the hepl of one or more symbols '|' (the vertical part) and symbols '+' and '-' as on the example which is given above.
     34 
     35 Brackets should be drawn without spaces one by one, only dividing pairs of consecutive pairwise brackets with a single-space bar (so that the two brackets do not visually merge into one symbol). The image should have the minimum possible height.
     36 
     37 The enclosed bracket is always smaller than the surrounding bracket, but each bracket separately strives to maximize the height of the image. So the pair of final brackets in the example above occupies the entire height of the image.
     38 
     39 Study carefully the examples below, they adequately explain the condition of the problem. Pay attention that in this problem the answer (the image) is unique.
     40 
     41 Input
     42 
     43 The first line contains an even integer *n* (2 ≤ *n* ≤ 100) — the length of the sequence of brackets.
     44 
     45 The second line contains the sequence of brackets — these are *n* symbols "[" and "]". It is guaranteed that the given sequence of brackets is regular.
     46 
     47 Output
     48 
     49 Print the drawn bracket sequence in the format which is given in the condition. Don't print extra (unnecessary) spaces.
     50 
     51 Examples
     52 
     53 Input
     54 
     55 ```
     56 8  
     57 [[][]][]
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 +-        -++- -+  
     64 |+- -++- -+||   |  
     65 ||   ||   |||   |  
     66 |+- -++- -+||   |  
     67 +-        -++- -+
     68 ```
     69 
     70 Input
     71 
     72 ```
     73 6  
     74 [[[]]]
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 +-     -+  
     81 |+-   -+|  
     82 ||+- -+||  
     83 |||   |||  
     84 ||+- -+||  
     85 |+-   -+|  
     86 +-     -+
     87 ```
     88 
     89 Input
     90 
     91 ```
     92 6  
     93 [[][]]
     94 ```
     95 
     96 Output
     97 
     98 ```
     99 +-        -+  
    100 |+- -++- -+|  
    101 ||   ||   ||  
    102 |+- -++- -+|  
    103 +-        -+
    104 ```
    105 
    106 Input
    107 
    108 ```
    109 2  
    110 []
    111 ```
    112 
    113 Output
    114 
    115 ```
    116 +- -+  
    117 |   |  
    118 +- -+
    119 ```
    120 
    121 Input
    122 
    123 ```
    124 4  
    125 [][]
    126 ```
    127 
    128 Output
    129 
    130 ```
    131 +- -++- -+  
    132 |   ||   |  
    133 +- -++- -+
    134 ```