690D1.md (2204B)
1 Source: https://codeforces.com/problemset/problem/690/D1 2 3 D1. The Wall (easy) 4 5 time limit per test 6 7 0.5 seconds 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 "The zombies are lurking outside. Waiting. Moaning. And when they come..." 22 23 "When they come?" 24 25 "I hope the Wall is high enough." 26 27 Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segments. We call on you for help. Go forth and explore the wall! Report how many disconnected segments there are. 28 29 The wall is a two-dimensional structure made of bricks. Each brick is one unit wide and one unit high. Bricks are stacked on top of each other to form columns that are up to *R* bricks high. Each brick is placed either on the ground or directly on top of another brick. Consecutive non-empty columns form a wall segment. The entire wall, all the segments and empty columns in-between, is *C* columns wide. 30 31 Input 32 33 The first line of the input consists of two space-separated integers *R* and *C*, 1 ≤ *R*, *C* ≤ 100. The next *R* lines provide a description of the columns as follows: 34 35 * each of the *R* lines contains a string of length *C*, 36 * the *c*-th character of line *r* is B if there is a brick in column *c* and row *R* - *r* + 1, and . otherwise. 37 38 The input will contain at least one character B and it will be valid. 39 40 Output 41 42 The number of wall segments in the input configuration. 43 44 Examples 45 46 Input 47 48 ``` 49 3 7 50 ....... 51 ....... 52 .BB.B.. 53 ``` 54 55 Output 56 57 ``` 58 2 59 ``` 60 61 Input 62 63 ``` 64 4 5 65 ..B.. 66 ..B.. 67 B.B.B 68 BBB.B 69 ``` 70 71 Output 72 73 ``` 74 2 75 ``` 76 77 Input 78 79 ``` 80 4 6 81 ..B... 82 B.B.BB 83 BBB.BB 84 BBBBBB 85 ``` 86 87 Output 88 89 ``` 90 1 91 ``` 92 93 Input 94 95 ``` 96 1 1 97 B 98 ``` 99 100 Output 101 102 ``` 103 1 104 ``` 105 106 Input 107 108 ``` 109 10 7 110 ....... 111 ....... 112 ....... 113 ....... 114 ....... 115 ....... 116 ....... 117 ....... 118 ...B... 119 B.BB.B. 120 ``` 121 122 Output 123 124 ``` 125 3 126 ``` 127 128 Input 129 130 ``` 131 8 8 132 ........ 133 ........ 134 ........ 135 ........ 136 .B...... 137 .B.....B 138 .B.....B 139 .BB...BB 140 ``` 141 142 Output 143 144 ``` 145 2 146 ``` 147 148 Note 149 150 In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second.