Submission
Status:
[PP-SSSSSSSSSSSSSSSSSSSSSS]
Score: 0
User: Nightingale
Problemset: เกาะที่ใหญ่ที่สุด
Language: cpp
Time: 0.002 second
Submitted On: 2025-03-27 15:20:13
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> island;
int a;
int b;
int explore(int row,int col){
int counter = 0;
island[row][col] = 2;
if(row-1>=0&&island[row-1][col]==1){
counter++;
counter = counter+explore(row-1,col);
}
if(row+1<a&&island[row+1][col]==1){
counter++;
counter = counter+explore(row+1,col);
}
if(col-1>=0&&island[row][col-1]==1){
counter++;
counter = counter+explore(row,col-1);
}
if(col+1<b&&island[row][col+1]==1){
counter++;
counter = counter+explore(row,col+1);
}
return counter;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int best = 0;
cin >> a >> b;
for(int i=0;i<a;i++){
island.push_back({});
string c;
cin >> c;
for(int j=0;j<b;j++){
island[i].push_back(int(c[j])-48);
}
}
int val = 0;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
if(island[i][j]==1) val = explore(i,j);
if(val>best) best = val;
}
}
if(best==0){
cout << 0;
return 0;
}
cout << best+1;
}