Submission

Status:

[PP-SSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: onlyme910

Problemset: fireball

Language: cpp

Time: 0.003 second

Submitted On: 2025-10-09 18:40:08

#include <bits/stdc++.h>
using namespace std;

int mapt[1000][1000];
int alive;

int main(){
    int N,M,f;
    cin >> N >> M >> f;
    int castle[f];
    for(int i = 0;i<N;i++){
        for(int j = 0;j<M;j++){
            cin >> mapt[i+1][j+1];
        }
    }
    for(int i = 0;i<f;i++){
        int x,y;
        cin >> x >> y;
        if(mapt[x][y] == 1){
            mapt[x][y] = 2;
            if(mapt[x+1][y] == 1)
                mapt[x+1][y] = 2;
            if(mapt[x-1][y] == 1)
                mapt[x-1][y] = 2;
            if(mapt[x][y+1] == 1)
                mapt[x][y+1] = 2;
            if(mapt[x][y-1] == 1)
                mapt[x][y-1] = 2;
        }

        alive = 0;
        for(int j = 0;j<N;j++){
            for(int k =0;k<M;k++){
                if(mapt[j+1][k+1] == 1){
                    alive++;
                }
            }
        }
        castle[i] = alive;

        for(int i = 0;i<N;i++){
            for(int j = 0;j<M;j++){
                if(mapt[x][y] == 2){
                    if(mapt[x+1][y] == 1)
                        mapt[x+1][y] = 2;
                    if(mapt[x-1][y] == 1)
                        mapt[x-1][y] = 2;
                    if(mapt[x][y+1] == 1)
                        mapt[x][y+1] = 2;
                    if(mapt[x][y-1] == 1)
                        mapt[x][y-1] = 2;
                }
            }
        }
    }
    for(int i =0;i < f;i++){
        cout << castle[i] << "\n";
    }
}