Submission

Status:

[PPPPPPPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: C12

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-03-09 22:52:00

#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9+7;

int posx[] = {0,0,-1,1};
int posy[] = {-1,1,0,0};


char board[171][171] = {0};
int vis[171][171] = {0};

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n,m;

    cin >> n >> m;

    stack<int>dfs;


    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin >> board[i][j];
            if(board[i][j] == '0') vis[i][j] = 1;
            // cout << board[i][j] << ' ';
        }
        // cout << '\n';
    }

    // return 0;

    int mx = 0;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if(vis[i][j]) continue;
            vis[i][j] = 1;

            dfs.push(i*m+j);

            int c = 0;
            while(!dfs.empty()){
                int x = dfs.top()/m;
                int y = dfs.top()%m;
                dfs.pop();

                c++;

                for(int k = 0;k < 4;k++){
                    int nx = x + posx[k];
                    int ny = y + posy[k];
                
                    if(nx < 0 || ny < 0 || nx >= n || ny >= m) continue;
                    if(vis[nx][ny]) continue;
                    vis[nx][ny] = 1;

                    dfs.push(nx*m+ny);
                }
            }
            mx = max(mx,c);
        }
    }
    cout << mx;


    return 0;
}

/*

7 16
This is an example of text justification.

6 16
What must be acknowledgement shall be

*/