|
11 | 11 |
|
12 | 12 | ## [803. Bricks Falling When Hit (Hard)](https://leetcode.com/problems/bricks-falling-when-hit "打砖块")
|
13 | 13 |
|
14 |
| -<p>We have a grid of 1s and 0s; the 1s in a cell represent bricks. A brick will not drop if and only if it is directly connected to the top of the grid, or at least one of its (4-way) adjacent bricks will not drop.</p> |
| 14 | +<p>You are given an <code>m x n</code> binary <code>grid</code>, where each <code>1</code> represents a brick. A brick will not drop if:</p> |
15 | 15 |
|
16 |
| -<p>We will do some erasures sequentially. Each time we want to do the erasure at the location (i, j), the brick (if it exists) on that location will disappear, and then some other bricks may drop because of that erasure.</p> |
| 16 | +<ul> |
| 17 | + <li>It is directly connected to the top of the grid, or</li> |
| 18 | + <li>At least one of its four adjacent bricks will not drop.</li> |
| 19 | +</ul> |
| 20 | + |
| 21 | +<p>You are also given an array <code>hits</code>. We will do some erasures sequentially. Each time we want to do the erasure at the location <code>hits[i] = (x<sub>i</sub>, y<sub>i</sub>)</code>, the brick (if it exists) on that location will disappear, and then some other bricks may drop because of that erasure.</p> |
| 22 | + |
| 23 | +<p>Return <em>an array representing the number of bricks that will drop after each erasure in sequence</em>.</p> |
17 | 24 |
|
18 |
| -<p>Return an array representing the number of bricks that will drop after each erasure in sequence.</p> |
| 25 | +<p><strong>Note</strong> that an erasure may refer to a location with no brick and if it does, no bricks drop.</p> |
| 26 | + |
| 27 | +<p> </p> |
| 28 | +<p><strong>Example 1:</strong></p> |
19 | 29 |
|
20 | 30 | <pre>
|
21 |
| -<strong>Example 1:</strong> |
22 |
| -<strong>Input:</strong> |
23 |
| -grid = [[1,0,0,0],[1,1,1,0]] |
24 |
| -hits = [[1,0]] |
| 31 | +<strong>Input:</strong> grid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]] |
25 | 32 | <strong>Output:</strong> [2]
|
26 |
| -<strong>Explanation: </strong> |
27 |
| -If we erase the brick at (1, 0), the brick at (1, 1) and (1, 2) will drop. So we should return 2.</pre> |
| 33 | +<strong>Explanation: </strong>If we erase the brick at (1, 0), the brick at (1, 1) and (1, 2) will drop. So we should return 2. |
| 34 | +</pre> |
| 35 | + |
| 36 | +<p><strong>Example 2:</strong></p> |
28 | 37 |
|
29 | 38 | <pre>
|
30 |
| -<strong>Example 2:</strong> |
31 |
| -<strong>Input:</strong> |
32 |
| -grid = [[1,0,0,0],[1,1,0,0]] |
33 |
| -hits = [[1,1],[1,0]] |
| 39 | +<strong>Input:</strong> grid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]] |
34 | 40 | <strong>Output:</strong> [0,0]
|
35 |
| -<strong>Explanation: </strong> |
36 |
| -When we erase the brick at (1, 0), the brick at (1, 1) has already disappeared due to the last move. So each erasure will cause no bricks dropping. Note that the erased brick (1, 0) will not be counted as a dropped brick.</pre> |
| 41 | +<strong>Explanation: </strong>When we erase the brick at (1, 0), the brick at (1, 1) has already disappeared due to the last move. So each erasure will cause no bricks dropping. |
| 42 | +Note that the erased brick (1, 0) will not be counted as a dropped brick. |
| 43 | +</pre> |
37 | 44 |
|
38 | 45 | <p> </p>
|
39 |
| - |
40 |
| -<p><strong>Note:</strong></p> |
| 46 | +<p><strong>Constraints:</strong></p> |
41 | 47 |
|
42 | 48 | <ul>
|
43 |
| - <li>The number of rows and columns in the grid will be in the range [1, 200].</li> |
44 |
| - <li>The number of erasures will not exceed the area of the grid.</li> |
45 |
| - <li>It is guaranteed that each erasure will be different from any other erasure, and located inside the grid.</li> |
46 |
| - <li>An erasure may refer to a location with no brick - if it does, no bricks drop.</li> |
| 49 | + <li><code>m == grid.length</code></li> |
| 50 | + <li><code>n == grid[i].length</code></li> |
| 51 | + <li><code>1 <= m, n <= 200</code></li> |
| 52 | + <li><code>grid[i][j]</code> is <code>0</code> or <code>1</code>.</li> |
| 53 | + <li><code>1 <= hits.length <= 4 * 10<sup>4</sup></code></li> |
| 54 | + <li><code>hits[i].length == 2</code></li> |
| 55 | + <li><code>0 <= x<sub>i </sub><= m - 1</code></li> |
| 56 | + <li><code>0 <= y<sub>i</sub> <= n - 1</code></li> |
| 57 | + <li>All <code>(x<sub>i</sub>, y<sub>i</sub>)</code> are unique.</li> |
47 | 58 | </ul>
|
48 | 59 |
|
49 | 60 | ### Related Topics
|
|
0 commit comments