60B.md (2504B)
1 Source: https://codeforces.com/problemset/problem/60/B 2 3 B. Serial Time! 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k* × *n* × *m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n* × *m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*, *y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment. 22 23 Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1 × 1 × 1 cubes. 24 25 Input 26 27 The first line contains three numbers *k*, *n*, *m* (1 ≤ *k*, *n*, *m* ≤ 10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1 ≤ *x* ≤ *n*, 1 ≤ *y* ≤ *m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*. 28 29 Output 30 31 The answer should contain a single number, showing in how many minutes the plate will be filled. 32 33 Examples 34 35 Input 36 37 ``` 38 1 1 1 39 40 . 41 42 1 1 43 ``` 44 45 Output 46 47 ``` 48 1 49 ``` 50 51 Input 52 53 ``` 54 2 1 1 55 56 . 57 58 # 59 60 1 1 61 ``` 62 63 Output 64 65 ``` 66 1 67 ``` 68 69 Input 70 71 ``` 72 2 2 2 73 74 .# 75 ## 76 77 .. 78 .. 79 80 1 1 81 ``` 82 83 Output 84 85 ``` 86 5 87 ``` 88 89 Input 90 91 ``` 92 3 2 2 93 94 #. 95 ## 96 97 #. 98 .# 99 100 .. 101 .. 102 103 1 2 104 ``` 105 106 Output 107 108 ``` 109 7 110 ``` 111 112 Input 113 114 ``` 115 3 3 3 116 117 .#. 118 ### 119 ##. 120 121 .## 122 ### 123 ##. 124 125 ... 126 ... 127 ... 128 129 1 1 130 ``` 131 132 Output 133 134 ``` 135 13 136 ```