Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Seng
Problemset: fireball
Language: cpp
Time: 0.003 second
Submitted On: 2026-06-27 11:02:57
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n, m, t;cin >> n >> m >> t;
int cnt = 0;
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
vector<vector<int>> v(n+1, vector<int>(m+1)), vis(n+1, vector<int>(m+1, false));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> v[i][j];
if(v[i][j] == 1) cnt++;
}
}
queue<pair<int, int>> q;
while(t--){
int a, b;cin >> a >> b;
q.push({a, b});
while(!q.empty()){
auto [y, x] = q.front();
q.pop();
if(v[y][x] == 1){
if(vis[y][x] == true) continue;
vis[y][x] = true;
cnt--;
for(int i = 0; i < 4; i++){
int xx = x+dx[i];
int yy = y+dy[i];
if(yy <= n && yy >= 1 && xx <= m && x >= 1 && v[yy][xx] == 1){
q.push({yy, xx});
}
}
}
}
cout << cnt << '\n';
}
}