Submission
Status:
[PPP-SSSSSSSSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: Pxnny
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-20 00:21:02
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
string grid[200];
int ct=0, n, m;
bool vis[200][200];
int yy[] = {-1, 0, 0, 1};
int xx[] = {0, -1, 1, 0};
void floodfill(int i, int j){
queue<pii> q;
q.push({i, j});
ct = 0;
while(!q.empty()){
ct++;
int y = q.front().first;
int x = q.front().second;
q.pop();
if(grid[y][x] == '0') continue;
grid[y][x] = '0';
for(i=0; i<4; i++){
int ny = y + yy[i];
int nx = x + xx[i];
if(ny<0 || ny>=n || nx<0 || nx>=m) continue;
if(grid[ny][nx] == '0') continue;
q.push({ny, nx});
}
}
}
int main(){
ios_base::sync_with_stdio(0), cin.tie(0);
int ans=-100;
cin >> n >> m;
for(int i=0; i<n; i++){
cin >> grid[i];
}
//cout << "hello";
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
ct = 0;
if(grid[i][j] != '0'){
//cout << i << " " << j << endl;
floodfill(i, j);
ans = max(ct, ans);
//cout << ct << endl;
}
}
}
cout << ans;
}
/*
4 4
0011
0000
0111
1100
8 13
0010000100000
0000000111000
0110100000000
0100110010100
0100110011100
0000000000100
0000000111000
0000000110000
*/