Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Brabra475
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.004 second
Submitted On: 2026-02-22 14:30:36
#include<bits/stdc++.h>
using namespace std;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
int main(){
int n,m;
cin>>n>>m;
vector<string> map(n);
for(int i =0 ;i < n ;i++){
cin>>map[i];
}
int mx=0;
for(int i =0 ;i< n;i++){
for(int j =0;j<m;j++){
if(map[i][j]=='1'){
int sum=1;
queue<pair<int,int>> pq;
pq.push({i,j});
map[i][j]='0';
while(pq.empty()!=true){
int keepi,keepj;
keepi=pq.front().first;
keepj=pq.front().second;
pq.pop();
for(int i = 0;i<4;i++){
int nx= keepi+dx[i];
int ny= keepj+dy[i];
if(nx>=0 && ny>=0 && nx<n && ny< m && map[nx][ny]=='1'){
map[nx][ny]='0';
pq.push({nx,ny});
sum++;
}
}
}
if(sum>mx){
mx=sum;
}
}
}
}
cout<<mx;
}