Submission
Status:
[PPPPPPPPPPPPxSS]
Subtask/Task Score:
{0/100}
Score: 0
User: ST68031
Problemset: fireball
Language: cpp
Time: 0.004 second
Submitted On: 2025-10-11 09:21:57
#include <bits/stdc++.h>
using namespace std;
int map1[100][100];
int x, y, z;
void burn(int a, int b){
if(map1[a][b] == 1){
map1[a][b] = 0;
if (b + 1 >= 0 && map1[a][b + 1] == 1){
burn(a, b + 1);
}
if (b - 1 >= 0 && map1[a][b - 1] == 1){
burn(a, b - 1);
}
if (a + 1 >= 0 && map1[a + 1][b] == 1){
burn(a + 1, b);
}
if (a - 1 >= 0 && map1[a - 1][b] == 1){
burn(a - 1, b);
}
}
}
int main(){
cin >> x >> y >> z;
for(int i = 0;i < x;i++){
for(int j = 0;j < y;j++){
cin >> map1[i][j];
}
}
int temp[z], count1 = 0;
int temp1 ,temp2;
for(int i = 0;i < z;i++){
count1 = 0;
cin >> temp1 >> temp2;
burn(temp1 - 1, temp2 - 1);
for(int j = 0;j < x;j ++){
for(int k = 0;k < y;k++){
if(map1[j][k] == 1){
count1++;
}
}
}
temp[i] = count1;
}
for(int i = 0;i < z;i++){
cout << temp[i] << endl;
}
}