62 x 61 x 60
이고#include <iostream>
#include <cstring>
using namespace std;
constexpr int d[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int N, M, virus_cnt;
int lab[8][8], lab_copy[8][8];
pair<int, int> virus[10];
int count_safearea() {
int ret = 0;
for (int y = 0; y < N; y++)
for (int x = 0; x < M; x++)
if (lab_copy[y][x] == 0) ret++;
return ret;
}
void DFS(int y, int x) {
lab_copy[y][x] = 2;
for (auto i : d) {
int ny = y + i[0], nx = x + i[1];
if (0 <= ny && ny < N && 0 <= nx && nx < M && !lab_copy[ny][nx]) DFS(ny, nx);
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin >> N >> M;
for (int y = 0; y < N; y++)
for (int x = 0; x < M; x++) {
cin >> lab[y][x];
if (lab[y][x] == 2) virus[virus_cnt++] = {y, x};
}
int answer = 0;
for (int i = 0, size = N * M; i < size; i++)
for (int j = i + 1; j < size; j++)
for (int k = j + 1; k < size; k++)
if (!lab[i / M][i % M] && !lab[j / M][j % M] && !lab[k / M][k % M]) {
/* copy lab ▶ make 3 walls ▶ DFS ▶ count */
memcpy(lab_copy, lab, sizeof(lab));
lab_copy[i / M][i % M] = lab_copy[j / M][j % M] = lab_copy[k / M][k % M] = 1;
for (int l = 0; l < virus_cnt; l++) DFS(virus[l].first, virus[l].second);
answer = max(answer, count_safearea());
}
cout << answer << '\n';
return 0;
}