Submission

Status:

[PPPPPPPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: kd

Problemset: เกาะที่ใหญ่ที่สุด

Language: cpp

Time: 0.003 second

Submitted On: 2026-02-19 22:12:25

#include<bits/stdc++.h>
using namespace std;
const int nx = 170+5;
const int mx = 170+5;
int n, m, curr_sz, ans;
int arr[nx][mx], vst[nx][mx];
string grid[nx];

void floodfill(int r, int c, int num){
    if(r<0||r>=n||c<0||c>=m) return;
    if(arr[r][c]!=num) return;
    if(vst[r][c]) return;
    vst[r][c] = 1;
    curr_sz++;
    floodfill(r, c+1, num);
    floodfill(r, c-1, num);
    floodfill(r+1, c, num);
    floodfill(r-1, c, num);
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>grid[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)  arr[i][j] = int(grid[i][j])-48;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(!vst[i][j]&&arr[i][j]==1){
                curr_sz = 0;
                floodfill(i, j, arr[i][j]);
                ans = max(ans, curr_sz);
            }
        }
    }
    cout<<ans;
}