Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: kimza
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.003 second
Submitted On: 2026-03-06 18:59:37
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n,m;
cin >> n >> m;
vector<string> mp;
for(int i=0;i<n;i++){
string s;
cin >> s;
mp.push_back(s);
}
int maxcnt = 0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(mp[i][j]=='1'){
int cnt = 0;
queue<pair<int,int>> q;
q.push({i,j});
mp[i][j]='0';
cnt++;
while(!q.empty()){
int y = q.front().first;
int x = q.front().second;
q.pop();
if(y+1<n && mp[y+1][x]=='1'){
q.push({y+1,x});
mp[y+1][x]='0';
cnt++;
}
if(x+1<m && mp[y][x+1]=='1'){
q.push({y,x+1});
mp[y][x+1]='0';
cnt++;
}
if(y-1>=0 && mp[y-1][x]=='1'){
q.push({y-1,x});
mp[y-1][x]='0';
cnt++;
}
if(x-1>=0 && mp[y][x-1]=='1'){
q.push({y,x-1});
mp[y][x-1]='0';
cnt++;
}
}
if(cnt > maxcnt) maxcnt = cnt;
}
}
}
cout << maxcnt;
return 0;
}