Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using pi = pair <int, int>;
- const int N = 30 + 10, M = 30 + 10;
- char ar[N][M];
- bool vs[N][M];
- int di[] = {0, 0, 1, -1};
- int dj[] = {1, -1, 0, 0};
- int n, m;
- bool pst(int i, int j){
- return 1 <= i and i <= n and 1 <= j and j <= m;
- }
- bool check(int i, int j){
- return ar[i][j] != '#' and
- ar[i][j + 1] != '#' and
- ar[i][j - 1] != '#' and
- ar[i + 1][j] != '#' and
- ar[i - 1][j] != '#';
- }
- int bfs(int si, int sj, int cnt = 0){
- queue <pi> q;
- q.push({si, sj});
- while(!q.empty()){
- int ui = q.front().first;
- int uj = q.front().second;
- q.pop();
- if(vs[ui][uj]) continue;
- vs[ui][uj] = true;
- cnt ++;
- for(int d=0;d<4;d++){
- int vi = ui + di[d];
- int vj = uj + dj[d];
- if(pst(vi, vj) and !vs[vi][vj] and check(vi, vj))
- q.push({vi, vj});
- }
- }
- return cnt;
- }
- int main(){
- scanf("%d %d", &n, &m);
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- scanf(" %c", &ar[i][j]);
- }
- }
- int mx = 0;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- if(!vs[i][j] and check(i, j))
- mx = max(mx, bfs(i, j));
- }
- }
- printf("%d", mx);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement