Submission

Status:

PPPPPPxxxxx

Score: 60

User: akuyga1

Problemset: ตั้งฐานทัพ

Language: cpp

Time: 0.053 second

Submitted On: 2024-11-29 17:51:56

#include<bits/stdc++.h>
using namespace std;

int c=0;
bool ins=false;
vector<int> comp;
queue<pair<int,int>> Q;

void fill(int x,int y,string A[],int W,int H){
    Q.push({x,y});
    while(!Q.empty()){
        int xx=Q.front().first,yy=Q.front().second;
        if(A[yy][xx]!='.')Q.pop();
        else{
            c++;
            Q.pop();
            A[yy][xx]='*';
            if(xx>0)Q.push({xx-1,yy});
            if(yy>0)Q.push({xx,yy-1});
            if(xx>0&&yy>0)Q.push({xx-1,yy-1});
            if(xx<W-1)Q.push({xx+1,yy});
            if(yy<H-1)Q.push({xx,yy+1});
            if(xx<W-1&&yy<H-1)Q.push({xx+1,yy+1});
            if(xx>0&&yy<H-1)Q.push({xx-1,yy+1});
            if(xx<W-1&&yy>0)Q.push({xx+1,yy-1});
            fill(0,0,A,W,H);
        }
    }
    //cout<<"YO";
    comp.push_back(c);c=0;}

int main(){
    int W,H;
    cin>>W>>H;
    string A[H];
    for(auto& i:A)cin>>i;
    //for(auto& i:A)cout<<i<<endl;
    for(int i=0;i<H;i++)for(int j=0;j<W;j++)if(A[i][j]=='.'){fill(j,i,A,W,H);}
    int m=0;
    for(auto i:comp)m=max(m,i);
    cout<<m;
}