Language: C++

#include <bits/stdc++.h>
#include <string>
#define INF 100000
using namespace std;
char x[1001][1001];
int H, W, N;
int cycle;
int tots;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
typedef pair<int, int> P;
queue<P> que; 

int count(){
    int ans = 1;
    int nl = 0; //now loop
    while(que.size()){
        P p = que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int ny = p.first+dy[i];
            int nx = p.second+dx[i];
            if(ny>=0 && ny < H && nx>=0 && nx < W && x[ny][nx] == '.'){
                que.push(P(ny,nx));
                x[ny][nx]='#';
                tots++;
                if(tots==H*W) return ans;
            }
        }
        nl++; 
 //       cout << cycle <<" "<< que.size() << " " << nl << endl;
        if(nl==cycle){
            ans++;
            cycle = que.size();
            nl = 0;
 
        }
    }
    return ans;
}

int main(){
    cin >> H >> W;
    tots =0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> x[i][j];
            if(x[i][j]=='#'){
             tots++;
             que.push(P(i,j));
            }
        }
    }
    cycle = que.size();
    cout << count() << endl;
}#include <bits/stdc++.h>
#include <string>
#define INF 100000
using namespace std;
char x[1001][1001];
int H, W, N;
int cycle;
int tots;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
typedef pair<int, int> P;
queue<P> que; 

int count(){
    int ans = 1;
    int nl = 0; //now loop
    while(que.size()){
        P p = que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int ny = p.first+dy[i];
            int nx = p.second+dx[i];
            if(ny>=0 && ny < H && nx>=0 && nx < W && x[ny][nx] == '.'){
                que.push(P(ny,nx));
                x[ny][nx]='#';
                tots++;
                if(tots==H*W) return ans;
            }
        }
        nl++; 
 //       cout << cycle <<" "<< que.size() << " " << nl << endl;
        if(nl==cycle){
            ans++;
            cycle = que.size();
            nl = 0;
 
        }
    }
    return ans;
}

int main(){
    cin >> H >> W;
    tots =0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> x[i][j];
            if(x[i][j]=='#'){
             tots++;
             que.push(P(i,j));
            }
        }
    }
    cycle = que.size();
    cout << count() << endl;
}

Compiler output:
a.cc:56:2: error: stray '#' in program
   56 | }#include <bits/stdc++.h>
      |  ^
a.cc:56:3: error: 'include' does not name a type
   56 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:60:6: error: redefinition of 'char x [1001][1001]'
   60 | char x[1001][1001];
      |      ^
a.cc:5:6: note: 'char x [1001][1001]' previously declared here
    5 | char x[1001][1001];
      |      ^
a.cc:61:5: error: redefinition of 'int H'
   61 | int H, W, N;
      |     ^
a.cc:6:5: note: 'int H' previously declared here
    6 | int H, W, N;
      |     ^
a.cc:61:8: error: redefinition of 'int W'
   61 | int H, W, N;
      |        ^
a.cc:6:8: note: 'int W' previously declared here
    6 | int H, W, N;
      |        ^
a.cc:61:11: error: redefinition of 'int N'
   61 | int H, W, N;
      |           ^
a.cc:6:11: note: 'int N' previously declared here
    6 | int H, W, N;
      |           ^
a.cc:62:5: error: redefinition of 'int cycle'
   62 | int cycle;
      |     ^~~~~
a.cc:7:5: note: 'int cycle' previously declared here
    7 | int cycle;
      |     ^~~~~
a.cc:63:5: error: redefinition of 'int tots'
   63 | int tots;
      |     ^~~~
a.cc:8:5: note: 'int tots' previously declared here
    8 | int tots;
      |     ^~~~
a.cc:64:5: error: redefinition of 'int dx [4]'
   64 | int dx[4] = {1, -1, 0, 0};
      |     ^~
a.cc:9:5: note: 'int dx [4]' previously defined here
    9 | int dx[4] = {1, -1, 0, 0};
      |     ^~
a.cc:65:5: error: redefinition of 'int dy [4]'
   65 | int dy[4] = {0, 0, 1, -1};
      |     ^~
a.cc:10:5: note: 'int dy [4]' previously defined here
   10 | int dy[4] = {0, 0, 1, -1};
      |     ^~
a.cc:67:10: error: redefinition of 'std::queue<std::pair<int, int> > que'
   67 | queue<P> que;
      |          ^~~
a.cc:12:10: note: 'std::queue<std::pair<int, int> > que' previously declared here
   12 | queue<P> que;
      |          ^~~
a.cc:69:5: error: redefinition of 'int count()'
   69 | int count(){
      |     ^~~~~
a.cc:14:5: note: 'int count()' previously defined here
   14 | int count(){
      |     ^~~~~
a.cc:97:5: error: redefinition of 'int main()'
   97 | int main(){
      |     ^~~~
a.cc:42:5: note: 'int main()' previously defined here
   42 | int main(){
      |     ^~~~