Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: APNICHANAN
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.004 second
Submitted On: 2026-02-25 08:29:19
#include <bits/stdc++.h>
using namespace std;
vector<string> s;
int k = 0, cnt = 0;
priority_queue<int> a;
int n, m;
int ok[1005][1005];
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
void dfs(int x, int y)
{
ok[x][y] = 1;
cnt++;
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || nx >= m || ny < 0 || ny >= n)
continue;
if (s[nx][ny] == '0' || ok[nx][ny] == 1)
continue;
dfs(nx, ny);
}
return;
}
int main()
{
cin >> m >> n;
for (int i = 0; i < m; i++)
{
string x;
cin >> x;
s.push_back(x);
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (s[i][j] == '1' && ok[i][j] != 1)
{
cnt = 0;
dfs(i, j);
a.push(cnt);
}
}
}
if (a.empty() == false)
cout << a.top() << "\n";
else
cout << 0 << "\n";
}