## LCC '23 Contest 2 S2 - How the Cookie Uncrumbles

View as PDF

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 baking sheet. This sheet can be thought of as a matrix of cells, with as the top-left cell and 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 minute.

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

#### Input Specification

The first line will contain , , and , space-separated.

The next lines will contain 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 minutes.

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

11

#### Explanation for Sample Output 1

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

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

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

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

3 2 1
.O
O.
O.

5