Submission
Status:
[PP-SSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: theem1502
Problemset: fireball
Language: cpp
Time: 0.002 second
Submitted On: 2026-02-17 15:53:07
#include <bits/stdc++.h>
using namespace std;
int dix[4] = {0,0,-1,1};
int diy[4] = {1,-1,0,0};
int row, collumn;
int dfs(int currentx, int currenty, vector<vector<int>> &thearray) {
if (currentx < 0 || currenty < 0 || currentx >= row || currenty >= collumn) {
// cout << "H";
return 0;
}
if (thearray[currentx][currenty] == 0) {
/*
cout << thearray[currentx][currenty] << "\n";
cout << currentx << " " << currenty << "\n\n";
for (int j = 0; j < row; j++) {
for (int k = 0; k < collumn; k++) {
cout << thearray[j][k] << " ";
}
cout << "\n";
}
*/
// cout << "F";
return 0;
}
thearray[currentx][currenty] = 0;
int sum = 1;
/*
cout << "curr" << currentx << " " << currenty << "\n";*/
for (int i = 0; i < 4; i++) {
// cout << "added " << i << " " << dix[i] << " " << diy[i] << "\n";
sum += dfs(currentx + dix[i], currenty + diy[i], thearray);
}
return sum;
}
int main() {
ios::sync_with_stdio(false);cin.tie(nullptr);
int q;
cin >> collumn >> row >> q;
int total = 0;
vector<vector<int>> thearray(row, vector<int> (collumn));
for (int i = 0 ; i < row; i++) {
for (int j = 0; j < collumn; j++) {
cin >> thearray[i][j];
if (thearray[i][j] == 1) total++;
}
}
// cout << "total = " << total << "\n";
for (int i = 0; i < q; i++) {
int x, y;
cin >> x >> y;
y--; x--;
// vector<vector<int>> cpyarray = thearray;
/*
for (int j = 0; j < row; j++) {
for (int k = 0; k < collumn; k++) {
cout << cpyarray[j][k] << " ";
}
cout << "\n";
}
*/
/*
for (int j = 0; j < row; j++) {
for (int k = 0; k < collumn; k++) {
cout << thearray[j][k] << " ";
}
cout << "\n";
}
*/
// cout << "x, y = " << x << " " << y << "\n";
// cout << "thing: " << cpyarray[x][y] << "\n";
int cnt = dfs(x, y,thearray);
// cout << "cnt = " << cnt << "\n";
cout << total-cnt << "\n";
}
}