Submission

Status:

[PPPPPPPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: kittipos

Problemset: เกาะที่ใหญ่ที่สุด

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-09 21:50:25

#include <bits/stdc++.h>

using namespace std;

int h, w;
vector<string> space;

int drop(int c, int r) {
    int cnt = 0;
    queue<pair<int, int>> q;
    q.push(make_pair(c, r));
    while (!q.empty()) {
        pair<int, int> cur = q.front();
        q.pop();
        
        int x = cur.first;
        int y = cur.second;
        if (x < 0 || y < 0 || x >= w || y >= h) continue;
        
        if (space[y][x] == '1') {
            cnt++;
            space[y][x] = '0';
        } else {
            continue;
        }
        // cout << "check point 1" << endl;

        q.push({x+1, y});
        q.push({x-1, y});
        q.push({x, y+1});
        q.push({x, y-1});
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> h >> w;
    space.resize(h);
    for (int i = 0; i < h; i++) {
        string temp;
        cin >> temp;
        space[i] = temp;
    }

    int most = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (space[i][j] == '1') {
                int area = drop(j, i);
                most = max(most, area);
            }
        }
    }

    cout << most;

    return 0;
}