Submission
Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]
Score: 100
User: Nightingale
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.006 second
Submitted On: 2025-04-01 14:20:00
#include <bits/stdc++.h>
using namespace std;
int a,b;
int best = 0;
int explore(vector<vector<int>> &island,int i,int j){
island[i][j] = 0;
int counter = 1;
if(i-1>=0&&island[i-1][j]==1){
counter+=explore(island,i-1,j);
}
if(j-1>=0&&island[i][j-1]==1){
counter+=explore(island,i,j-1);
}
if(i+1<a&&island[i+1][j]==1){
counter+=explore(island,i+1,j);
}
if(j+1<b&&island[i][j+1]==1){
counter+=explore(island,i,j+1);
}
return counter;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> b;
vector<vector<int>> island(a,vector<int>(b));
string inp;
for(int i=0;i<a;i++){
cin >> inp;
for(int j=0;j<b;j++){
island[i][j] = int(inp[j])-48;
}
}
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
if(island[i][j]==1){
int fucl = explore(island,i,j);
if(fucl>best) best = fucl;
}
}
}
cout << best;
}