#include #include using namespace std; bool grid[100000] = {0}; int ground[100000] = {0}; size_t fall_count = 0; size_t rows, cols, tp_count; void step() { for (int row = rows - 1; row >= 1; row--) { for (int col = cols - 1; col >= 0; col--) { if (!grid[row * cols + col] && grid[(row-1) * cols + col]) { grid[row * cols + col] = true; grid[(row-1) * cols + col] = false; if (ground[col] == row+1) { fall_count++; ground[col] = row; } } } } } int main() { cin.tie(NULL); std::ios::sync_with_stdio(false); string line; cin >> rows >> cols >> tp_count; for (int i = 0; i < cols; i++) { ground[i] = rows; } getline(cin, line); for (int i = 0; i < rows; i++) { getline(cin, line); for (int j = 0; j < cols; j++) { grid[i*cols + j ] = line[j] == '*'; if (i == rows-1 && line[j] == '*') { fall_count++; ground[j] = rows-1; } } } for (int row = rows - 1; row >= 1; row--) { for (int col = cols - 1; col >= 0; col--) { if (grid[row * cols + col] && ground[col] == row+1) { fall_count++; ground[col] = row; } } } size_t astep = 0; size_t tstep = 0; for (int i = 0; i < tp_count; i++) { cin >> tstep; for (; astep < tstep; astep++) { step(); } cout << fall_count << '\n'; } return 0; }