Submission
Status:
[-SSSSSSSSSSSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: C12
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.002 second
Submitted On: 2026-01-04 12:53:37
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair<ll,ll>
#define puii pair<ull,ull>
#define piii pair<ll,pii>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define mpiii(a,b,c) make_pair(a,make_pair(b,c));
// ll mod = 1000000007;
ll x,y,nx,ny;
ll n,m;
int board[171][171];
ll cnt;
ll mx = 0;
queue<pii>q;
int posx[4] = {-1,1,0,0};
int posy[4] = {0,0,-1,1};
void dfs(){
cnt = 0;
while(!q.empty()){
x = q.front().f;
y = q.front().s;
q.pop();
cnt++;
for(int k = 0;k < 4;k++){
nx = x + posx[k];
ny = y + posy[k];
if(nx < 0 || ny < 0 || nx >= n || ny >= m)
continue;
if(board[nx][ny] == 1){
q.push(mp(nx,ny));
board[nx][ny] = 0;
}
}
}
// if(cnt > 1){
// mx = max(cnt,mx);
// }
}
void solve(){
cin >> n >> m;
string s;
for(int i = 0;i < n;i++){
cin >> s;
for(int j = 0;j < m;j++){
board[i][j] = s[j] - '0';
}
}
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
if(board[i][j] == 1){
board[i][j] = 0;
q.push(mp(i,j));
dfs();
}
}
}
cout << mx;
return;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll q;
// cin >> q;
// while(q--)
solve();
return 0;
}