Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: SnowAveNode
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.003 second
Submitted On: 2026-03-01 08:42:31
#include <bits/stdc++.h>
using namespace std;
int n, m, area, ans = 0;
vector<vector<int>> v;
void dfs(int y, int x) {
if(y < 0 || y >= n || x < 0 || x >= m) return;
if(v[y][x] == 0) return;
v[y][x] = 0;
area++;
dfs(y-1, x);
dfs(y+1, x);
dfs(y, x-1);
dfs(y, x+1);
}
int main() {
cin >> n >> m;
v.assign(n, vector<int>(m));
for(int i = 0; i < n; i++) {
string s; cin >> s;
for(int j = 0; j < m; j++)
v[i][j] = s[j] - '0';
}
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) {
area = 0;
if(v[i][j] == 1) {dfs(i, j);}
ans = max(ans, area);
}
cout << ans;
return 0;
}