Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: tull
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.004 second
Submitted On: 2026-06-02 22:47:38
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define bp '\n'
#define ld long double
#define vp cout<<'\n';
#define all(A) A.begin(),A.end()
using pii=pair<int,int>;
const int MOD=1e9+7;
const int MNLL=-1e18;
const int MXLL=1e18;
const int N=2e5+10;
const string sans[]={"NO","YES"};
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n,m;
cin>>n>>m;
vector<string>a(n);
for(auto&e:a)cin>>e;
vector<vector<int>>vst(n,vector<int>(m,0));
pii dir[]={{1,0},{0,1},{-1,0},{0,-1}};
auto BFS=[&](int i,int j){
int cnt=0;
queue<pii>q;
q.emplace(i,j);
while(!q.empty()){
auto[i,j]=q.front();
q.pop();
if(vst[i][j])continue;
vst[i][j]=1;
++cnt;
for(auto&[f,s]:dir){
int o=i+f,p=j+s;
if(o<0 or o>=n or p<0 or p>=m or vst[o][p] or a[o][p]=='0')continue;
q.emplace(o,p);
}
}
return cnt;
};
int ans=0;
for(int i=0;i<n;++i){
for(int j=0;j<m;++j){
if(a[i][j]=='0' or vst[i][j])continue;
ans=max(ans,BFS(i,j));
}
}
cout<<ans;
}