Submission
Status:
[PxSSSSSSSSSSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: kittipos
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-09 21:49:09
#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<string> space;
int drop(int c, int r) {
int cnt = 0;
queue<pair<int, int>> q;
q.push(make_pair(c, r));
while (!q.empty()) {
pair<int, int> cur = q.front();
q.pop();
int x = cur.first;
int y = cur.second;
if (x < 0 || y < 0 || x >= w || y >= h) continue;
if (space[x][y] == '1') {
cnt++;
space[x][y] = '0';
} else {
continue;
}
q.push({x+1, y});
q.push({x-1, y});
q.push({x, y+1});
q.push({x, y-1});
}
return cnt;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> h >> w;
space.resize(h);
for (int i = 0; i < h; i++) {
string temp;
cin >> temp;
space[i] = temp;
}
int most = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (space[i][j] == '1') {
int area = drop(j, i);
most = max(most, area);
}
}
}
cout << most;
return 0;
}