Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: erng
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.003 second
Submitted On: 2025-11-23 15:03:16
#include <bits/stdc++.h>
using namespace std;
int n, m, vs[175][175], di[4]={1, 0, -1, 0}, dj[4]={0, 1, 0, -1}, ans;
char mp[175][175];
queue<pair<int,int>> q;
stack<int> r;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++)
{
cin>>mp[i][j];
}
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++)
{
if (mp[i][j]=='1' && vs[i][j]==0)
{
vs[i][j]=1;
q.push({i, j});
ans=1;
while (!q.empty())
{
auto [ni, nj]=q.front();
q.pop();
for (int k=0; k<4; k++)
{
int ci=ni+di[k], cj=nj+dj[k];
if (vs[ci][cj]) continue;
if (mp[ci][cj]=='1')
{
ans++;
vs[ci][cj]=1;
q.push({ci, cj});
}
}
}
r.push(ans);
}
}
}
ans=0;
while (!r.empty())
{
ans=max(r.top(), ans);
r.pop();
}
cout<<ans;
}