Language: C++

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int neighs[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};

char t[1000][1000],c[1000][1000];
int h,w;

void copy(int a) {
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (a) c[i][j] = t[i][j];
            else t[i][j] = c[i][j];
        }
    }
}

void solve() {
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> t[i][j];
        }
    }

    int cnt=0;
    while (true) {

        bool flag = false;
        
        copy(1);

        for (int i =  0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
             if (t[i][j] == '#') {
                for (auto n : neighs) {
                    int x = i+n[0];
                    int y = j+n[1];
                    if (x>=0&&x<h&&y>=0&&y<w&&c[x][y]=='.') {
                        c[x][y] = '#';
                        flag = true;
                    }
                }

            }
        }
    }

    copy(0);

    if (!flag) {
        break;
    } else {
        ++cnt;
    }
}

cout << cnt << '\n';
}

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
	#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

	#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

  return 0;
}

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

//#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int neighs[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};

char t[1000][1000],c[1000][1000];
int h,w;

void copy(int a) {
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (a) c[i][j] = t[i][j];
            else t[i][j] = c[i][j];
        }
    }
}

void solve() {
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> t[i][j];
        }
    }

    int cnt=0;
    while (true) {

        bool flag = false;
        
        copy(1);

        for (int i =  0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
             if (t[i][j] == '#') {
                for (auto n : neighs) {
                    int x = i+n[0];
                    int y = j+n[1];
                    if (x>=0&&x<h&&y>=0&&y<w&&c[x][y]=='.') {
                        c[x][y] = '#';
                        flag = true;
                    }
                }

            }
        }
    }

    copy(0);

    if (!flag) {
        break;
    } else {
        ++cnt;
    }
}

cout << cnt << '\n';
}

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
	#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

	#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

  return 0;
}

//////// End Initialization ///////////////////////////////////////

Compiler output:
a.cc:104:11: error: redefinition of 'const int neighs [4][2]'
  104 | const int neighs[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
      |           ^~~~~~
a.cc:12:11: note: 'const int neighs [4][2]' previously defined here
   12 | const int neighs[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
      |           ^~~~~~
a.cc:106:6: error: redefinition of 'char t [1000][1000]'
  106 | char t[1000][1000],c[1000][1000];
      |      ^
a.cc:14:6: note: 'char t [1000][1000]' previously declared here
   14 | char t[1000][1000],c[1000][1000];
      |      ^
a.cc:106:20: error: redefinition of 'char c [1000][1000]'
  106 | char t[1000][1000],c[1000][1000];
      |                    ^
a.cc:14:20: note: 'char c [1000][1000]' previously declared here
   14 | char t[1000][1000],c[1000][1000];
      |                    ^
a.cc:107:5: error: redefinition of 'int h'
  107 | int h,w;
      |     ^
a.cc:15:5: note: 'int h' previously declared here
   15 | int h,w;
      |     ^
a.cc:107:7: error: redefinition of 'int w'
  107 | int h,w;
      |       ^
a.cc:15:7: note: 'int w' previously declared here
   15 | int h,w;
      |       ^
a.cc:109:6: error: redefinition of 'void copy(int)'
  109 | void copy(int a) {
      |      ^~~~
a.cc:17:6: note: 'void copy(int)' previously defined here
   17 | void copy(int a) {
      |      ^~~~
a.cc:118:6: error: redefinition of 'void solve()'
  118 | void solve() {
      |      ^~~~~
a.cc:26:6: note: 'void solve()' previously defined here
   26 | void solve() {
      |      ^~~~~
a.cc:165:5: error: redefinition of 'int main()'
  165 | int main() {
      |     ^~~~
a.cc:73:5: note: 'int main()' previously defined here
   73 | int main() {
      |     ^~~~