Submission
Status:
[PPPxSSSSSSSSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: Shangbin
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.003 second
Submitted On: 2026-01-24 22:54:58
//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}};
char mat[maxn][maxn];
vector<int> island;
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){
if (mat[qi + nx][qj + ny] == '1'){
q.push({qi + nx, qj + ny});
}
}
}
island.push_back(islandsize);
}
}
}
//for (auto i : island) cout << i << ' ';
cout << *max_element(island.begin(), island.end());
}