Submission

Status:

[-SSSSSSSSSSSSSSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: Quaoar

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

Language: cpp

Time: 0.003 second

Submitted On: 2025-12-31 22:21:03

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int n,m;
string line;
int cnt = 0;
int mx = -1;
int map[171][171];
int visited[171][171];
void re(int x , int y){
    if (map[x][y] == 1) return;
    if (visited[x][y]) return;
    map[x][y] = 1;
    visited[x][y] = true;
    if (x - 1 >= 0) re(x - 1 , y);
    if (x + 1 < n) re(x + 1 , y);
    if (y - 1 >= 0) re(x , y - 1);
    if (y + 1 < m) re(x , y + 1);
    cnt++;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 0 ; i < n ; i++){
        cin >> line;
        for (int j = 0 ; j < m ; j++){
            int temp = line[j] - '0';
            map[i][j] = temp;
        }
    }

    for (int i = 0 ; i < n ; i++){
        for (int j = 0 ; j < m ; j++){
            if (map[i][j] == 1){
                continue;
            }
            re(i,j);
            /*
            for (int a = 0 ; a < n ; a++){
                for (int b = 0 ;b < m ; b++){
                    cout << map[a][b] << " ";
                }
                cout << "\n";
            }
            cout << cnt << " " << mx << "\n";
            */
            mx = max(mx , cnt);
            cnt = 0;
        }
    }
    cout << mx;
}