Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: navysrimuang
Problemset: fireball
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-18 21:07:10
#include<bits/stdc++.h>
using namespace std;
int n,m,q;
int lc = 0;
int g[102][102],vis[102][102];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
void dfs(int x,int y){
vis[x][y] = 1;
lc--;
for(int i = 0;i<4;i++){
int xx = x+dx[i]; int yy = y+dy[i];
if(!(xx > n || xx < 1 || yy > m || yy < 1) && !vis[xx][yy] && g[xx][yy]) dfs(xx,yy);
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> q;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin >> g[i][j];
if(g[i][j]) lc++;
}
}
while(q--){
int x,y;
cin >> x >> y;
if(g[x][y] && !vis[x][y]) dfs(x,y);
cout << lc << "\n";
}
return 0;
}