Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: singtoppy
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.003 second
Submitted On: 2026-02-08 13:45:06
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> v(n, vector<int>(m));
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
char c;
cin >> c;
v[i][j] = c - '0';
}
}
const int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int res = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(v[i][j] == 0) {
continue;
}
queue<pair<int, int>> q;
q.push({i, j});
int cnt = 0;
while(!q.empty()) {
auto [y, x] = q.front();
q.pop();
if(v[y][x] == 0) {
continue;
}
cnt++;
res = max(res, cnt);
v[y][x] = 0;
for(const auto& d : dir) {
const int nx = x + d[1];
const int ny = y + d[0];
if(nx >= 0 && nx < m && ny >= 0 && ny < n && v[ny][nx] != 0) {
q.push({ny, nx});
}
}
}
}
}
cout << res;
return 0;
}