Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: kd

Problemset: fireball

Language: cpp

Time: 0.004 second

Submitted On: 2026-02-19 23:01:45

#include<bits/stdc++.h>
using namespace std;
const int nx = 105;
int n, m, q, mx, r, c, cnt;
int arr[nx][nx], vst[nx][nx];

void floodfill(int r, int c){
    if(r<1||r>n||c<1||c>m) return;
    if(arr[r][c]==0||vst[r][c]) return;
    vst[r][c] = 1;
    floodfill(r, c+1);
    floodfill(r, c-1);
    floodfill(r+1, c);
    floodfill(r-1, c);
    cnt--;
}

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>>arr[i][j];
            if(arr[i][j]==1) cnt++;
        }
    }
    for(int i=0;i<q;i++){
        cin>>r>>c;
        floodfill(r, c);
        cout<<cnt<<"\n";
    }
}