Submission

Status:

[-SSSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: goine

Problemset: anna

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-10 20:08:32

#include <iostream>
#include <vector>

using namespace std;

int h, w;
vector<vector<int>> world_map;
vector<vector<bool>> visited;

int alive = 0;

void burn(int x, int y) {
    if (x < 0 || y < 0 || x >= w || y >= h) return;
    if (visited[y][x]) return;
    if (world_map[y][x] != 1) return;
    
    visited[y][x] = true;
    world_map[y][x] = 2;
    alive--;
    
    burn(x - 1, y);
    burn(x + 1, y);
    burn(x, y - 1);
    burn(x, y + 1);
}

int main() {
	int c;
	cin >> h >> w >> c;

	world_map.resize(h, vector<int>(w));
	visited.resize(h, vector<bool>(w, false));

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> world_map[i][j];
			if (world_map[i][j] == 1) alive++;
		}
	}

	vector<int> results;

	for (int i = 0; i < c; i++) {
		int x, y;
		cin >> x >> y;
		burn(y-1, x-1);
		results.push_back(alive);
	}

	for (int i = 0; i < c; i++) {
		cout << results[i] << endl;
	}

	return 0;
}