Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: kittipos
Problemset: fireball
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-08 19:40:20
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> space;
int cnt = 0;
int h, w;
void drop(int x, int y) {
if (space[y][x] == 0) {
// cout << "check point 2" << endl;
return;
}
// cout << "check point 3, x: " << x << ", y: " << y << endl;
queue<pair<int, int>> q;
q.push({x, y});
while (!q.empty()) {
pair<int, int> cur = q.front();
q.pop();
if (
cur.first < 0 ||
cur.first >= w ||
cur.second < 0 ||
cur.second >= h
) continue;
// cout << "check point 2, x: " << cur.first << ", y: " << cur.second << endl;
if (space[cur.second][cur.first] == 1) {
cnt--;
} else {
continue;
}
space[cur.second][cur.first] = 0;
q.push({cur.first+1, cur.second});
q.push({cur.first-1, cur.second});
q.push({cur.first, cur.second+1});
q.push({cur.first, cur.second-1});
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> h >> w >> n;
space.assign(h, vector<int>(w));
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> space[i][j];
if (space[i][j] == 1) {
cnt++;
}
}
}
for (int i = 0; i < n; i++) {
int x, y;
cin >> y >> x;
x--; y--;
// cout << "check point 1" << endl;
drop(x, y);
cout << cnt << '\n';
// for (int j = 0; j < h; j++) {
// for (int k = 0; k < w; k++) {
// cout << space[j][k] << ' ';
// }
// cout << endl;
// }
// cout << endl;
}
return 0;
}