Submission
Status:
[PPP-SSSSSSSSSSSSSSSSSSSSS]
Score: 0
User: qwerty
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.003 second
Submitted On: 2025-03-25 20:54:46
// 51
#include<bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> dis = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
vector<string> mappu;
vector<vector<bool>> vis;
int bfs(int i, int j) {
int c = 0;
queue<pair<int, int>> q;
q.push({i, j});
while (!q.empty()) {
int x = q.front().first;
int y = q.front().second;
q.pop();
if (vis[x][y]) continue;
vis[x][y] = true;
c++;
for (auto d : dis) {
int nx = x+d.first;
int ny = y+d.second;
if (nx>=0 && nx<n && ny>=0 && ny<m && !vis[nx][ny] && mappu[nx][ny]=='1') {
q.push({nx, ny});
}
}
}
return c;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
mappu.resize(n);
for (int i = 0 ; i < n ; i++) {
cin >> mappu[i];
}
vis.resize(n, vector<bool>(m, false));
int ans = INT_MIN;
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < m ; j++) {
if (!vis[i][j] && mappu[i][j]=='1') {
ans = max(ans, bfs(i, j));
}
}
}
cout << ans;
}
/*8 13 0010000100000 0000000111000 0110100000000 0100110010100 0100110011100 0000000000100 0000000111000 0000000110000*/