https://www.acmicpc.net/problem/2638

비슷한 유형의 문제를 여러번 풀어봐서 크게 고민하지는 않았습니다.
#include <iostream>
#include <queue>
using namespace std;
int n, m;
int maps[101][101];
bool vi[101][101];
queue<pair<int, int>> q;
int dx[4]{ 0,0,1,-1 };
int dy[4]{ 1,-1,0,0 };
bool solve() {
	fill(&vi[0][0], &vi[100][101], false);
	q.push({ 0,0 });
	vi[0][0] = true;
	while (!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
			if (maps[nx][ny] >= 1) maps[nx][ny]++;
			else {
				if (!vi[nx][ny]) {
					vi[nx][ny] = true;
					q.push({ nx,ny });
				}
			}
		}
	}
	
	bool check = false;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (maps[i][j] >= 3) {
				maps[i][j] = 0;
				check = true;
			}
			if (maps[i][j] >= 1) {
				maps[i][j] = 1;
			}
		}
	}
	return check;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> maps[i][j];
		}
	}
	int cnt = 0;
	while (solve()) cnt++;
	cout << cnt;
}
무난한 bfs dfs 문제였습니다.