LCC '23 Contest 2 S2 - How the Cookie Uncrumbles

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types

Because MCPT has stolen SAC's idea to sell hotdogs at food day, Zoe decides to bake cookies instead.

Currently, she has an N \times M baking sheet. This sheet can be thought of as a matrix of cells, with (1, 1) as the top-left cell and (N, M) as the bottom-right.

Zoe has placed cookie dough on some cells and has just placed the sheet in the oven. However, she forgets that cookie dough expands when baking. A strange phenomenon happens as a result: if a cell not containing cookie dough is cardinally adjacent (horizontally or vertically) to at least two other cells containing cookie dough, the cookie dough will fill that cell after 1 minute.

Fascinated, Zoe wonders how many cells contain cookie (not dough anymore!) if she bakes the cookies for K minutes.

Constraints

For all subtasks,

1 \le N, M \le 10^3

1 \le K \le 10^9

Subtask 1 [25%]

1 \le N, M, K \le 50

Subtask 2 [75%]

No additional constraints.

Input Specification

The first line will contain N, M, and K, space-separated.

The next N lines will contain M O or . characters, denoting whether there is cookie dough at that cell, or not, respectively.

Output Specification

Output a single integer on one line: how many cells contain cookie if she baked the cookies for K minutes.

Sample Input 1

6 6 10
..O...
.....O
.OO...
......
.....O
....O.

Sample Output 1

11

Explanation for Sample Output 1

The following diagrams describe how the cookie dough expands after 1, 2, and 3 minutes respectively. After three minutes the cookie dough no longer expands, and Zoe is left with 11 cells containing cookie.

..O...
..O..O
.OO...
......
....OO
....OO

..O...
.OO..O
.OO...
......
....OO
....OO

.OO...
.OO..O
.OO...
......
....OO
....OO

Sample Input 2

3 2 1
.O
O.
O.

Sample Output 2

5

Comments


  • 0
    marsflat  commented on Dec. 2, 2023, 1:10 a.m. edited

    Since the original data were weak, a new test case has been added and all submissions have been rejudged.