Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: spiwips
Problemset: fireball
Language: cpp
Time: 0.006 second
Submitted On: 2025-12-16 20:55:58
//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]||vs[x][y])
{
cout<<counter;
cout<<'\n';
continue;
}
counter--;
//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();
//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;
counter --;
}
}
//checking stuff
}
cout<<counter;
cout<<'\n';
}
}