Submission

Status:
[PPPPPPPPPPPPPPPPPPPPPPPPP]

Score: 100

User: Nathlol2

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

Language: cpp

Time: 0.006 second

Submitted On: 2025-03-25 20:38:48

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define tiii tuple<int, int, int>
#define ar array
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>
#define ff first
#define ss second
#define rep(i,s,e) for(long long int i=s;i<e;i++)
#define cf(i,s,e) for(long long int i=s;i<=e;i++)
#define rf(i,e,s) for(long long int i=e;i>=s;i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
template <class T>
void print_v(vector<T> &v) { for (auto x : v) cout << x << " "; cout << "\n"; }
#define MX INT_MAX
#define MN INT_MIN
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define read(type) readInt<type>()
ll min(ll a,int b) { if (a<b) return a; return b; }
ll min(int a,ll b) { if (a<b) return a; return b; }
ll max(ll a,int b) { if (a>b) return a; return b; }
ll max(int a,ll b) { if (a>b) return a; return b; }
ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }
bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; }
void YY() { cout<<"YES\n"; }
void NN() { cout<<"NO\n"; }
void Yes() { cout<<"Yes\n"; }
void No() { cout<<"No\n"; }
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
int mx[] = {0, 0, -1, 1};
int my[] = {1, -1, 0, 0};
void dfs(int x, int y, vector<vector<bool>> &vis, vector<vector<char>> &a, int n, int m, int &c){
    c++;
    vis[x][y] = true;
    for(int i = 0;i<4;i++){
        int nx = x + mx[i];
        int ny = y + my[i];
        if(nx >= 0 && ny >= 0 && nx < n && ny < m && !vis[nx][ny] && a[nx][ny] == '1'){
            dfs(nx, ny, vis, a, n, m, c);
        }
    }
}
void solve(){
    int n, m;
    cin >> n >> m;
    vector<vector<char>> a(n, vector<char>(m));
    vector<vector<bool>> vis(n, vector<bool>(m, false));
    int c = 0, ans = 0;
    rep(i, 0, n){
        rep(j, 0, m){
            cin >> a[i][j];
        }
    }
    rep(i, 0, n){
        rep(j, 0, m){
            if(!vis[i][j] && a[i][j] == '1'){
                c = 0;
                dfs(i, j, vis, a, n, m, c);
                ans = max(ans, c);
            }
        }
    }
    cout << ans << '\n';
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc = 1;
    //cin >> tc;
    while(tc--){
        solve();
    }
}