Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPP-S]
Subtask/Task Score:
{0/100}
Score: 0
User: navysrimuang
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.004 second
Submitted On: 2026-03-14 11:39:42
#include<bits/stdc++.h>
using namespace std;
int n,m;
int mx = INT_MIN;
int sz;
bool grid[200][200];
bool vis[200][200];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
char c; cin >> c;
if(c == '1') grid[i][j] = 1;
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(!vis[i][j]){
vis[i][j] = 1;
sz = 0;
stack<pair<int,int>> st;
st.push({i,j});
while(st.size()){
auto [x,y] = st.top();
st.pop();
for(int i = 0;i<4;i++){
int xx = x+dx[i]; int yy = y+dy[i];
if(xx > n || yy > m || xx <= 0 || yy <= 0 || !grid[xx][yy] || vis[xx][yy]) continue;
vis[xx][yy] = 1;
sz++;
st.push({xx,yy});
}
}
mx = max(mx,sz);
}
}
}
cout << mx << "\n";
return 0;
}