Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: SnowAveNode
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.003 second
Submitted On: 2026-04-10 18:21:11
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int nx = 1e5 + 5, MOD = 1e9 + 7, inf = 2e9; const ll INF = 4e18;
int dy[] = {-1, 1, 0, 0}, dx[] = {0, 0, -1, 1};
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m; cin >> n >> m; ll ans = 0;
vector<vector<char>> grid(n, vector<char>(m));
for(auto &x : grid) for(auto &y : x) cin >> y;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(grid[i][j] == '1') {
ll area = 0;
stack<pair<int, int>> st;
st.push({i, j});
grid[i][j] = '0';
area++;
while(!st.empty()) {
auto [y, x] = st.top(); st.pop();
for(int k = 0; k < 4; k++) {
int ny = y + dy[k], nx = x + dx[k];
if(ny < 0 || ny >= n || nx < 0 || nx >= m) continue;
if(grid[ny][nx] == '0') continue;
grid[ny][nx] = '0';
area++;
st.push({ny, nx});
}
}
ans = max(ans, area);
}
cout << ans << '\n';
return 0;
}