Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Fifaxmb
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.003 second
Submitted On: 2026-05-31 21:17:11
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
pii dxy[] = {{1,0},{-1,0},{0,-1},{0,1}};
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;cin >> n >> m;
vector<string> v(n);
queue<pii> q;
vector<vector<bool>> vis(n,vector<bool> (m,0));
for(int i =0;i < n;i++) cin >> v[i];
int ans = 0;
for(int i =0;i <n;i++){
for(int j =0;j < m;j++){
if(v[i][j] == '1' && !vis[i][j]){
int cnt = 1;
q.push({i,j});
vis[i][j] = 1;
while(!q.empty()){
auto [x,y] = q.front();q.pop();
for(int d = 0;d < 4;d++){
auto[xx,yy] = dxy[d];
xx += x;yy += y;
if(xx < 0 || yy < 0 || xx >= n || yy >= m || vis[xx][yy] || !(v[xx][yy] - '0')) continue;
cnt ++;
q.push({xx,yy});
vis[xx][yy] = 1;
}
}
ans = max(ans,cnt);
}
}
}
cout << ans;
}