Submission

Status:

PPPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: anonymous

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

Language: cpp

Time: 0.016 second

Submitted On: 2026-10-20 15:59:17

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

int mx[] = {0,0,1,-1,1,-1,1,-1};
int my[] = {1,-1,0,0,1,-1,-1,1};
#define pii pair<int,int>
int main(){
    int x,y; cin >> x >> y;
    vector<string> arr;
    for(int i=0;i<y;i++){
        string s; cin >> s;
        arr.push_back(s);
    }

    int ans = 0;
    for(int i=0;i<y;i++){
        for(int j=0;j<x;j++){
            if(arr[i][j] == '.'){
                queue<pii> q;
                q.push({i,j});
                int cnt = 1;
                while(!q.empty()){
                    int m = q.front().first;
                    int n = q.front().second;
                    arr[m][n] = '*';
                    q.pop();

                    for(int k=0;k<8;k++){
                        int nx = m+mx[k];
                        int ny = n+my[k];
                        if(0<=nx&&nx<y&&0<=ny&&n<x&&arr[nx][ny] == '.'){
                            q.push({nx,ny});
                            arr[nx][ny] = '*';
                            cnt++;
                        }
                    }
                }
                ans = max(cnt,ans);
            }
        }
    }
    cout << ans;
    return 0;
}