Submission

Status:

[PP-SSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: spiwips

Problemset: fireball

Language: cpp

Time: 0.003 second

Submitted On: 2025-12-16 14:54:25

//i might use x,y wrong bc im kinda confused lmao
#include<bits/stdc++.h>
using namespace std;
int counter = 0;
int n,m,q;
int board[105][105];
int vs[105][105];

//graph nav things
int dir1[4] = {0,0,1,-1},dir2[4] = {-1,1,0,0};

int main()
{
	cin>>n>>m>>q;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			cin>>board[i][j];
			if(board[i][j])
			{
				counter++;
			}
		}
	}
	vector<pair<int,int>> bombs;
	int x,y;
	for(int i = 0; i < q; i ++)
	{
		cin>>x>>y;
		bombs.push_back({x,y});
	}
	
	for(int i = 0; i < q; i ++){
		queue<pair<int,int>> note;
		x = bombs[i].first;
		y = bombs[i].second;
		
		if(!board[x][y])
		{
			cout<<counter;
			cout<<'\n';
			continue;
		}
		//graph navigation stuff
		note.push({x,y});
		vs[x][y] = 1;
		while(note.size()>0){
			int cx = note.front().first;
			int cy = note.front().second;
			note.pop();
			counter --;
			//checking stuff
			for(int j = 0; j < 4; j++){
				int new_x = cx+dir1[j];
				int new_y = cy+dir2[j];
				if(board[new_x][new_y]&&!vs[new_x][new_y]){
					note.push({new_x,new_y});
					vs[new_x][new_y] = 1;
				}
				
			}
			//checking stuff	
		}
		cout<<counter;
		cout<<'\n';
	}
}