Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Fifaxmb
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.004 second
Submitted On: 2026-08-11 20:45:32
#include<bits/stdc++.h>
using namespace std;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;cin >> n >> m;
vector<string> v(n);
vector<vector<bool>> vis(n,vector<bool>(m,0));
for(int i =0;i < n;i++) cin >> v[i];
int mx =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;
queue<pair<int,int>> q;
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++){
int xx = x + dx[d];
int yy = y + dy[d];
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;
}
}
mx = max(cnt,mx);
}
}
}
cout << mx;
}