Submission
Status:
[PPP-SSSSSSSSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: Shangbin
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.002 second
Submitted On: 2026-01-24 22:57:09
//Problem = https://grader.gchan.moe/problemset/c2_st66_largest_island
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
const int maxn = 175;
int m, n, visited[maxn][maxn], islandsize, dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}, biggest = -1e9;
char mat[maxn][maxn];
queue<pii> q;
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> mat[i][j];
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (mat[i][j] == '1'){
q.push({i, j});
islandsize = 0;
while (!q.empty()){
auto [qi, qj] = q.front(); q.pop();
if (visited[qi][qj]) continue;
visited[qi][qj] = 1;
islandsize++;
for (auto [nx, ny] : dir){
nx += qi, ny += qj;
if (mat[nx][ny] == '1'){
if (!visited[nx][ny]) q.push({nx, ny});
}
}
}
biggest = max(biggest, islandsize);
}
}
}
//for (auto i : island) cout << i << ' ';
cout << biggest;
}