#include #include #include using namespace std; int main() { int H, W, N; cin >> H >> W >> N; vector grid(H); for (int i = 0; i < H; ++i) { string line; cin >> line; grid[i] = line; } vector positions(N); for (int i = 0; i < N; ++i) { cin >> positions[i]; } vector blocks(N, "........."); // 3x3 blocks initialized to all '.' for (int i = N - 1; i >= 0; --i) { int c = positions[i]; bool found = false; // Try to find the highest possible position where the block could have landed for (int r = 0; r < H - 2; ++r) { // Check if the 3x3 block starting at (r, c) can be a valid block bool can_remove = true; for (int dr = 0; dr < 3; ++dr) { for (int dc = 0; dc < 3; ++dc) { if (grid[r + dr][c + dc] == '.' && blocks[i][dr * 3 + dc] == '#') { can_remove = false; break; } } if (!can_remove) break; } if (can_remove) { // Check if the block has at least one '#' bool has_block = false; for (int dr = 0; dr < 3; ++dr) { for (int dc = 0; dc < 3; ++dc) { if (grid[r + dr][c + dc] == '#') { has_block = true; break; } } if (has_block) break; } if (!has_block) continue; // Now, try to determine the block's shape string block(9, '.'); for (int dr = 0; dr < 3; ++dr) { for (int dc = 0; dc < 3; ++dc) { if (grid[r + dr][c + dc] == '#') { block[dr * 3 + dc] = '#'; grid[r + dr][c + dc] = '.'; } } } blocks[i] = block; found = true; break; } } if (!found) { // Handle cases where no block is found (shouldn't happen per problem statement) blocks[i] = "###......"; // Placeholder, though problem says input is valid } } for (const string &block : blocks) { for (int i = 0; i < 3; ++i) { cout << block.substr(i * 3, 3) << endl; } } return 0; }