Hypothermia
Time limit2sMemory limit1024 MB
Given an N by M grid of normal and hypothermic people, count those who stay at normal temperature forever when at most K can fall ill each night.
Problem
rows by columns of people are gathered in a rectangle. At the start, each person is either at normal body temperature or suffering from hypothermia, and their states change as days and nights pass. During the day, the warmth gives hypothermia patients a chance to recover. If a person has two or more orthogonally adjacent people at normal body temperature, that person shares their warmth and recovers from hypothermia to normal body temperature. After a person recovers, that person can help recover other adjacent people in the same way, and this recovery process can be repeated many times during the day. At night, it is cold, so people at normal body temperature can fall into hypothermia. However, at most people newly fall into hypothermia during a single night. Assume days and nights keep repeating, so people keep falling into hypothermia or recovering. Some people may never recover from hypothermia permanently. Other people have enough normal-temperature neighbors nearby that they can still recover during the day, no matter which people fall ill each night. Given the state of the people on the first day, find the number of people who, after days and nights have repeated many times, still keep normal body temperature during the day in the worst case.
Input
The first line contains three integers , , and , separated by spaces: the number of rows, the number of columns, and the maximum number of people who can newly fall into hypothermia at night. (; )
From the second line, lines follow, each a string of length . The -th character of the -th line gives the initial state of the person in row , column . O means normal body temperature, and . means hypothermia. All characters are guaranteed to be O or ..
Output
Print the number of people who, even after days and nights repeat indefinitely, keep normal body temperature during the day.