Submission

Status:

T--T-T-TT-T-T--xxxxx

Subtask/Task Score:

0/100

Score: 0

User: nigger123

Problemset: Abacus

Language: cpp

Time: 1.099 second

Submitted On: 2025-10-10 11:34:35

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

int width, height;
vector<bool> visited;
vector<vector<int>> worldMap;

bool inBounds(int x, int y) {
    return x >= 0 && x < width && y >= 0 && y < height;
}

void dfs(int x, int y) {
    if (!inBounds(x, y)) return;

    int idx = y * width + x;
    if (visited[idx]) return;
    if (worldMap[y][x] == 0) return;

    visited[idx] = true;

    dfs(x - 1, y);
    dfs(x + 1, y);
    dfs(x, y - 1);
    dfs(x, y + 1);
}

int main() {
    int fireball_count;
    int water = 0;

    cin >> height >> width >> fireball_count;

    worldMap.resize(height, vector<int>(width));
    for (int i = 0; i < height; ++i) {
        for (int j = 0; j < width; ++j) {
            cin >> worldMap[i][j];
            if (worldMap[i][j] == 0) water++;
        }
    }

    visited.resize(height * width, false);

    for (int i = 0; i < fireball_count; ++i) {
        int x, y;
        cin >> x >> y;

        dfs(x, y);
    
        int unvisited = count(visited.begin(), visited.end(), false);
        cout << unvisited - water << endl;
    }

    return 0;
}