Submission

Status:

[PPPPPPPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: goine

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-03-23 17:19:04

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

vector<string> mp;
int mx = 0;

int w, m;
void search(int x, int y) {
    if (mp[x][y] != '1') return;
    queue<pair<int, int>> q;
    int count = 0;
    
    q.push({x, y});

    while (!q.empty()) {
        auto n = q.front();
        q.pop();
        
        if (n.second < 0 || n.second >= m) continue;
        if (n.first < 0 || n.first >= w) continue;
        
        if (mp[n.first][n.second] != '1') continue;
        mp[n.first][n.second] = '2';

        int i = n.first, j = n.second;
        q.push({i + 1, j});
        q.push({i - 1, j});
        q.push({i, j - 1});
        q.push({i, j + 1});
        
        count++;
    }

    mx = max(count, mx);
}

int main() {
    cin >> w >> m;

    mp.resize(w);
    for (int i = 0; i < w; i++) {
        cin >> mp[i];
    }

    for (int i = 0; i < w; i++) {
        for (int j = 0; j < m; j++) {
            search(i, j);
        }
    }

    cout << mx << '\n';
    return 0;
}