Submission

Status:

[PPP-SSSSSSSSSSSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: Wha

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

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-08 23:28:03

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

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main() {
    vector<vector<int>> sea;
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        string t;
        cin >> t;
        vector<int> r;
        for (int j = 0; j < w; j++) {
            r.push_back(t[j] - '0');
        }
        sea.push_back(r);
    }
    int mx = -1;
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (sea[i][j] == 1) {
                int count = 0;
                queue<pair<int, int>> land;
                land.push({i, j});
                while (!land.empty()) {
                    count++;
                    auto cur = land.front();
                    sea[cur.first][cur.second] = -1;
                    land.pop();
                    for (int k = 0; k < 4; k++) {
                        if (cur.first + dy[k] < 0 || cur.first + dy[k] > h - 1 || cur.second + dx[k] < 0 || cur.second + dx[k] > w - 1 || sea[cur.first + dy[k]][cur.second + dx[k]] != 1) { continue; }
                        land.push({ cur.first + dy[k], cur.second + dx[k] });
                    }
                }
                mx = max(mx, count);
            }
        }
    }
    cout << mx << "\n";
    return 0;
}