Language: C++

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> vec;
	for (int i = 0; i < h; i++) {
		string t;
		cin >> t;
		vec.emplace_back(t);
	}
	set<pair<int, int>> se;
	for (int i = 1; i < h - 1; i++) {
		for (int j = 1; j < w - 1; j++) {
			if (vec[i][j] == '.')continue;
			int cnt = 0;
			for (int k = -1; k <= 1; k++) {
				for (int l = -1; l <= 1; l++) {
					if (i == 0 && j == 0)continue;
					if (vec[i + k][j + l] == '.') {
						cnt++;
					}
				}
			}
			if (cnt >= vec[i][j] - '0') {
				se.insert(make_pair(i, j));
			}
		}
	}
	for (auto i : se) {
		vec[i.first][i.second] = '.';
	}
	int ans = 0;
	for (;; ans++) {
		if (se.empty())break;
		set<pair<int, int>> temp;
		for (auto i : se) {
			for (int j = -1; j <= 1; j++) {
				for (int k = -1; k <= 1; k++) {
					if (j == 0 && k == 0)continue;
					int x = i.first + j, y = i.second + k;
					if (vec[x][y] == '.')continue;
					int cnt = 0;
					for (int l = -1; l <= 1; l++) {
						for (int m = -1; m <= 1; m++) {
							if (l == 0 && m == 0)continue;
							if (vec[x + l][y + m] == '.') {
								cnt++;
							}
						}
					}
					if (cnt >= vec[x][y] - '0') {
						temp.insert(make_pair(x, y));
					}
				}
			}
		}
		se = temp;
		for (auto i : se) {
			vec[i.first][i.second] = '.';
		}
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:3:9: error: 'cin' was not declared in this scope
    3 |         cin >> h >> w;
      |         ^~~
a.cc:4:9: error: 'vector' was not declared in this scope
    4 |         vector<string> vec;
      |         ^~~~~~
a.cc:4:16: error: 'string' was not declared in this scope
    4 |         vector<string> vec;
      |                ^~~~~~
a.cc:4:24: error: 'vec' was not declared in this scope
    4 |         vector<string> vec;
      |                        ^~~
a.cc:6:23: error: expected ';' before 't'
    6 |                 string t;
      |                       ^~
      |                       ;
a.cc:7:24: error: 't' was not declared in this scope
    7 |                 cin >> t;
      |                        ^
a.cc:10:9: error: 'set' was not declared in this scope
   10 |         set<pair<int, int>> se;
      |         ^~~
a.cc:10:13: error: 'pair' was not declared in this scope
   10 |         set<pair<int, int>> se;
      |             ^~~~
a.cc:10:18: error: expected primary-expression before 'int'
   10 |         set<pair<int, int>> se;
      |                  ^~~
a.cc:24:33: error: 'se' was not declared in this scope
   24 |                                 se.insert(make_pair(i, j));
      |                                 ^~
a.cc:24:43: error: 'make_pair' was not declared in this scope
   24 |                                 se.insert(make_pair(i, j));
      |                                           ^~~~~~~~~
a.cc:28:23: error: 'se' was not declared in this scope
   28 |         for (auto i : se) {
      |                       ^~
a.cc:33:21: error: 'se' was not declared in this scope
   33 |                 if (se.empty())break;
      |                     ^~
a.cc:34:26: error: expected primary-expression before 'int'
   34 |                 set<pair<int, int>> temp;
      |                          ^~~
a.cc:35:31: error: 'se' was not declared in this scope
   35 |                 for (auto i : se) {
      |                               ^~
a.cc:40:52: error: 'y' was not declared in this scope
   40 |                                         if (vec[x][y] == '.')continue;
      |                                                    ^
a.cc:45:72: error: 'y' was not declared in this scope
   45 |                                                         if (vec[x + l][y + m] == '.') {
      |                                                                        ^
a.cc:50:59: error: 'y' was not declared in this scope
   50 |                                         if (cnt >= vec[x][y] - '0') {
      |                                                           ^
a.cc:51:49: error: 'temp' was not declared in this scope
   51 |                                                 temp.insert(make_pair(x, y));
      |                                                 ^~~~
a.cc:51:61: error: 'make_pair' was not declared in this scope
   51 |                                                 temp.insert(make_pair(x, y));
      |                                                             ^~~~~~~~~
a.cc:56:17: error: 'se' was not declared in this scope
   56 |                 se = temp;
      |                 ^~
a.cc:56:22: error: 'temp' was not declared in this scope
   56 |                 se = temp;
      |                      ^~~~
a.cc:61:9: error: 'cout' was not declared in this scope
   61 |         cout << ans << endl;
      |         ^~~~
a.cc:61:24: error: 'endl' was not declared in this scope
   61 |         cout << ans << endl;
      |                        ^~~~