BOJ 15683. ๊ฐ์
๐โโ๏ธ[Gold IV] ๊ฐ์ - 15683
์ฑ๋ฅ ์์ฝ
๋ฉ๋ชจ๋ฆฌ: 2024 KB, ์๊ฐ: 24 ms
๋ถ๋ฅ
๋ฐฑํธ๋ํน, ๋ธ๋ฃจํธํฌ์ค ์๊ณ ๋ฆฌ์ฆ, ๊ตฌํ, ์๋ฎฌ๋ ์ด์
์ ์ถ ์ผ์
2024๋ 2์ 9์ผ 23:08:06
๋ฌธ์ ์ค๋ช
์คํํธ๋งํฌ์ ์ฌ๋ฌด์ค์ 1ร1ํฌ๊ธฐ์ ์ ์ฌ๊ฐํ์ผ๋ก ๋๋์ด์ ธ ์๋ NรM ํฌ๊ธฐ์ ์ง์ฌ๊ฐํ์ผ๋ก ๋ํ๋ผ ์ ์๋ค. ์ฌ๋ฌด์ค์๋ ์ด K๊ฐ์ CCTV๊ฐ ์ค์น๋์ด์ ธ ์๋๋ฐ, CCTV๋ 5๊ฐ์ง ์ข ๋ฅ๊ฐ ์๋ค. ๊ฐ CCTV๊ฐ ๊ฐ์ํ ์ ์๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ๋ค.
1๋ฒ | 2๋ฒ | 3๋ฒ | 4๋ฒ | 5๋ฒ |
1๋ฒ CCTV๋ ํ ์ชฝ ๋ฐฉํฅ๋ง ๊ฐ์ํ ์ ์๋ค. 2๋ฒ๊ณผ 3๋ฒ์ ๋ ๋ฐฉํฅ์ ๊ฐ์ํ ์ ์๋๋ฐ, 2๋ฒ์ ๊ฐ์ํ๋ ๋ฐฉํฅ์ด ์๋ก ๋ฐ๋๋ฐฉํฅ์ด์ด์ผ ํ๊ณ , 3๋ฒ์ ์ง๊ฐ ๋ฐฉํฅ์ด์ด์ผ ํ๋ค. 4๋ฒ์ ์ธ ๋ฐฉํฅ, 5๋ฒ์ ๋ค ๋ฐฉํฅ์ ๊ฐ์ํ ์ ์๋ค.
CCTV๋ ๊ฐ์ํ ์ ์๋ ๋ฐฉํฅ์ ์๋ ์นธ ์ ์ฒด๋ฅผ ๊ฐ์ํ ์ ์๋ค. ์ฌ๋ฌด์ค์๋ ๋ฒฝ์ด ์๋๋ฐ, CCTV๋ ๋ฒฝ์ ํต๊ณผํ ์ ์๋ค. CCTV๊ฐ ๊ฐ์ํ ์ ์๋ ์์ญ์ ์ฌ๊ฐ์ง๋๋ผ๊ณ ํ๋ค.
CCTV๋ ํ์ ์ํฌ ์ ์๋๋ฐ, ํ์ ์ ํญ์ 90๋ ๋ฐฉํฅ์ผ๋ก ํด์ผ ํ๋ฉฐ, ๊ฐ์ํ๋ ค๊ณ ํ๋ ๋ฐฉํฅ์ด ๊ฐ๋ก ๋๋ ์ธ๋ก ๋ฐฉํฅ์ด์ด์ผ ํ๋ค.
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 6 0 0 0 0 0 0 0
์ง๋์์ 0์ ๋น ์นธ, 6์ ๋ฒฝ, 1~5๋ CCTV์ ๋ฒํธ์ด๋ค. ์์ ์์์์ 1๋ฒ์ ๋ฐฉํฅ์ ๋ฐ๋ผ ๊ฐ์ํ ์ ์๋ ์์ญ์ '#
'๋ก ๋ํ๋ด๋ฉด ์๋์ ๊ฐ๋ค.
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 # 6 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 0 0 0 0 # # 1 0 6 0 0 0 0 0 0 0 |
0 0 # 0 0 0 0 0 # 0 0 0 0 0 1 0 6 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 6 0 0 0 # 0 0 0 |
โ | โ | โ | โ |
CCTV๋ ๋ฒฝ์ ํต๊ณผํ ์ ์๊ธฐ ๋๋ฌธ์, 1๋ฒ์ด โ ๋ฐฉํฅ์ ๊ฐ์ํ๊ณ ์์ ๋๋ 6์ ์ค๋ฅธ์ชฝ์ ์๋ ์นธ์ ๊ฐ์ํ ์ ์๋ค.
0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 6 0 0 6 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5
์์ ์์์์ ๊ฐ์ํ ์ ์๋ ๋ฐฉํฅ์ ์์๋ณด๋ฉด ์๋์ ๊ฐ๋ค.
0 0 0 0 0 # # 2 # # # # 0 0 0 0 6 # 0 6 # # 2 # 0 0 0 0 0 # # # # # # 5 |
0 0 0 0 0 # # 2 # # # # 0 0 0 0 6 # 0 6 0 0 2 # 0 0 0 0 # # # # # # # 5 |
0 # 0 0 0 # 0 2 0 0 0 # 0 # 0 0 6 # 0 6 # # 2 # 0 0 0 0 0 # # # # # # 5 |
0 # 0 0 0 # 0 2 0 0 0 # 0 # 0 0 6 # 0 6 0 0 2 # 0 0 0 0 # # # # # # # 5 |
์ผ์ชฝ ์๋จ 2: โ, ์ค๋ฅธ์ชฝ ํ๋จ 2: โ | ์ผ์ชฝ ์๋จ 2: โ, ์ค๋ฅธ์ชฝ ํ๋จ 2: โ | ์ผ์ชฝ ์๋จ 2: โ, ์ค๋ฅธ์ชฝ ํ๋จ 2: โ | ์ผ์ชฝ ์๋จ 2: โ, ์ค๋ฅธ์ชฝ ํ๋จ 2: โ |
CCTV๋ CCTV๋ฅผ ํต๊ณผํ ์ ์๋ค. ์๋ ์์๋ฅผ ๋ณด์.
0 0 2 0 3 0 6 0 0 0 0 0 6 6 0 0 0 0 0 0
์์ ๊ฐ์ ๊ฒฝ์ฐ์ 2์ ๋ฐฉํฅ์ด โ 3์ ๋ฐฉํฅ์ด โ์ โ์ธ ๊ฒฝ์ฐ ๊ฐ์๋ฐ๋ ์์ญ์ ๋ค์๊ณผ ๊ฐ๋ค.
# # 2 # 3 0 6 # 0 # 0 0 6 6 # 0 0 0 0 #
์ฌ๋ฌด์ค์ ํฌ๊ธฐ์ ์ํ, ๊ทธ๋ฆฌ๊ณ CCTV์ ์ ๋ณด๊ฐ ์ฃผ์ด์ก์ ๋, CCTV์ ๋ฐฉํฅ์ ์ ์ ํ ์ ํด์, ์ฌ๊ฐ ์ง๋์ ์ต์ ํฌ๊ธฐ๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์ ๋ ฅ
์ฒซ์งธ ์ค์ ์ฌ๋ฌด์ค์ ์ธ๋ก ํฌ๊ธฐ N๊ณผ ๊ฐ๋ก ํฌ๊ธฐ M์ด ์ฃผ์ด์ง๋ค. (1 โค N, M โค 8)
๋์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์๋ ์ฌ๋ฌด์ค ๊ฐ ์นธ์ ์ ๋ณด๊ฐ ์ฃผ์ด์ง๋ค. 0์ ๋น ์นธ, 6์ ๋ฒฝ, 1~5๋ CCTV๋ฅผ ๋ํ๋ด๊ณ , ๋ฌธ์ ์์ ์ค๋ช ํ CCTV์ ์ข ๋ฅ์ด๋ค.
CCTV์ ์ต๋ ๊ฐ์๋ 8๊ฐ๋ฅผ ๋์ง ์๋๋ค.
์ถ๋ ฅ
์ฒซ์งธ ์ค์ ์ฌ๊ฐ ์ง๋์ ์ต์ ํฌ๊ธฐ๋ฅผ ์ถ๋ ฅํ๋ค.
๐ํ์ด
๋ธ๋ฃจํธํฌ์ค๋ก ๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ํ์ํด์ ํ์๋ค.
enum Dir
{
UP, // 0
RIGHT, // 1
DOWN, // 2
LEFT, // 3
};
int n, m, cctvCount, ch[20], res = 123456789;
vector<vector<int>> board;
vector<vector<int>> visited;
vector<pair<int, int>> cctvs;
int dy[] = { -1, 0, 1, 0 };
int dx[] = { 0, 1, 0, -1 };
์ด๋ ๊ฒ ์ ์ญ ๋ณ์๋ฅผ ์ก์๊ณ , cctv๋ง๋ค ๊ฐ์ํ๋ ๋ฒ์๊ฐ ๋ค๋ฅด๋ฏ๋ก ๊ฐ๊ฐ์ ํจ์๋ฅผ ๋ง๋ค์ด์คฌ๋ค.
void CCTV1(int y, int x, int dir)
{
int curY = y;
int curX = x;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
}
void CCTV2(int y, int x, int dir)
{
int curY = y;
int curX = x;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
dir = (dir + 2) % 4;
y = curY;
x = curX;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
}
void CCTV3(int y, int x, int dir)
{
int curY = y;
int curX = x;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
y = curY;
x = curX;
dir = (dir + 1) % 4;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
}
void CCTV4(int y, int x, int dir)
{
int curY = y;
int curX = x;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
y = curY;
x = curX;
dir = (dir + 1) % 4;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
y = curY;
x = curX;
dir = (dir + 2) % 4;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
}
void CCTV5(int y, int x, int dir)
{
int curY = y;
int curX = x;
for (int i = 1; i <= 4; ++i)
{
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
dir = (dir + i) % 4;
y = curY;
x = curX;
}
}
๋ฌธ์ ์ ์กฐ๊ฑด๋๋ก ๊ฐ์๋ฅผ ํ๊ณ ๋ฐฉํฅ์ ์ค์ ํ๋ฉด ๊ทธ ๋ฐฉํฅ์ ๊ธฐ์ค์ผ๋ก ๊ฐ์งํ๋ ํจ์์ด๋ค.
๊ฒฐ๊ณผ๋ฅผ ํ์ธํ๋ ํจ์์ ๊ฒฐ๊ณผ ํ์ธ์ ์ํด visited๋ฅผ ์ด๊ธฐํํ๋ ํจ์๋ ๋ง๋ค์๋ค.
void visitedClear()
{
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
visited[i][j] = 0;
}
}
}
int checkResult()
{
int res = 0;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
if (board[i][j] == 1 || board[i][j] == 2 || board[i][j] == 3 || board[i][j] == 4 || board[i][j] == 5 || board[i][j] == 6)
continue;
if (visited[i][j] == 0 )
res++;
}
}
return res;
}
๋ชจ๋ ์ํฉ์ ํ์ํ๊ธฐ ์ํด์ ์ค๋ณต ๊ฐ๋ฅํ ์์ด์ ๋ง๋ค์๋ค.
DFS๋ผ๋ฅธ ์ด๋ฆ์ผ๋ก ๋ง๋ค์๋ค.
void DFS(int s, int L)
{
if (L == cctvCount)
{
for (int i = 0; i < L; ++i)
{
// ch[i] ๊ฐ dir
// i๋ cctv์ธ๋ฑ์ค
if (board[cctvs[i].first][cctvs[i].second] == 1)
{
CCTV1(cctvs[i].first, cctvs[i].second, ch[i]);
}
else if (board[cctvs[i].first][cctvs[i].second] == 2)
{
CCTV2(cctvs[i].first, cctvs[i].second, ch[i]);
}
else if (board[cctvs[i].first][cctvs[i].second] == 3)
{
CCTV3(cctvs[i].first, cctvs[i].second, ch[i]);
}
else if (board[cctvs[i].first][cctvs[i].second] == 4)
{
CCTV4(cctvs[i].first, cctvs[i].second, ch[i]);
}
else if (board[cctvs[i].first][cctvs[i].second] == 5)
{
CCTV5(cctvs[i].first, cctvs[i].second, ch[i]);
}
}
res = min(res, checkResult());
//printVisited();
visitedClear();
//cout << ch[i] << " ";
//cout << endl;
}
else
{
for (int i = 0; i < 4; ++i)
{
ch[L] = i;
DFS(i + 1, L + 1);
}
}
}
์์ ํจ์๋ฅผ ์ด์ฉํด์ ์ต์ข ์ ์ผ๋ก solveํจ์๋ฅผ ๋ง๋ค์๋ค.
void solve()
{
cin >> n >> m;
board = vector<vector<int>>(n + 1, vector<int>(m + 1));
visited = vector<vector<int>>(n + 1, vector<int>(m + 1));
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
cin >> board[i][j];
if (board[i][j] >= 1 && board[i][j] <= 5)
cctvs.push_back({ i, j });
}
}
cctvCount = cctvs.size();
DFS(0, 0);
cout << res;
// cctv๊ฐ 3๊ฐ
// ๊ฒฝ์ฐ์ ์
// 0 0 0
// 0 0 1
// 0 0 2
// 0 0 3
// 0 1 0
// 0 1 1
// 0 1 2
// 0 1 3
// 0 2 0
// ...
// 4 * 4 * 4
// 64
}
๊ณจ๋4 ๋ฌธ์ ์๋๋ฐ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ์ฐพ์ผ๋ ค๊ณ ์๊ฐ์ ๋ง์ด ์ผ๋ค.
๊ฒฐ๊ตญ์ ๋ฌด์ํ๊ฒ ํธ๋ ๋ฐฉ์์ผ๋ก ํ๋ํ๋ ํจ์๋ฅผ ๋ง๋ค์ด์ ํ์๋ค.
๋ฌธ์ ์ ์ถ์์๋ ํ๋ฒ๋ ํ๋ฆฌ์ง ์๊ณ ๋ฐ๋ก ๋ง์ถฐ์ ์ข์๋ค.
๐์ ์ฒด ์ฝ๋
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include<iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
void CCTV1(int y, int x, int dir);
void CCTV2(int y, int x, int dir);
void CCTV3(int y, int x, int dir);
void CCTV4(int y, int x, int dir);
void CCTV5(int y, int x, int dir);
void visitedClear();
int checkResult();
void solve();
// 1๋ฒ : ํ์ชฝ ๋ฐฉํฅ๋ง ์ฒดํฌ
// 2๋ฒ : ์ ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก ์ฒดํฌ (ํ ๋ผ์ธ ์ฒดํฌ)
// 3๋ฒ : ์ง๊ฐ ๋ฐฉํฅ์ผ๋ก ์ฒดํฌ
// 4๋ฒ : ํ ๋ฐฉํฅ์ผ๋ก ์ ์ธํ๊ณ ์ฒดํฌ
// 5๋ฒ : ๋ชจ๋ ๋ฐฉํฅ ์ฒดํฌ
// cctv๋ ์ต๋ 8๊ฐ์ด๋ค.
// ํ๋์ cctv๋ ์ต๋ 4๋ฒ ๊ฒฝ์ฐ์ ์๊ฐ ์กด์ฌํ๋ค. -> ๋ธ๋ฃจํธํฌ์ค๋ก ํด๋ ๋ ๊ฑฐ๊ฐ๋ค.
// ๋ฒํธ๋ง๋ค ์ฒดํฌํ๋ ๋ฐฉ๋ฒ์ด ํ์ํ๋ค.
enum Dir
{
UP, // 0
RIGHT, // 1
DOWN, // 2
LEFT, // 3
};
int n, m, cctvCount, ch[20], res = 123456789;
vector<vector<int>> board;
vector<vector<int>> visited;
vector<pair<int, int>> cctvs;
int dy[] = { -1, 0, 1, 0 };
int dx[] = { 0, 1, 0, -1 };
void CCTV1(int y, int x, int dir)
{
int curY = y;
int curX = x;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
}
void CCTV2(int y, int x, int dir)
{
int curY = y;
int curX = x;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
dir = (dir + 2) % 4;
y = curY;
x = curX;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
}
void CCTV3(int y, int x, int dir)
{
int curY = y;
int curX = x;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
y = curY;
x = curX;
dir = (dir + 1) % 4;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
}
void CCTV4(int y, int x, int dir)
{
int curY = y;
int curX = x;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
y = curY;
x = curX;
dir = (dir + 1) % 4;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
y = curY;
x = curX;
dir = (dir + 2) % 4;
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
}
void CCTV5(int y, int x, int dir)
{
int curY = y;
int curX = x;
for (int i = 1; i <= 4; ++i)
{
while (true)
{
int ny = y + dy[dir];
int nx = x + dx[dir];
if (ny < 1 || nx < 1 || ny > n || nx > m)
break;
if (board[ny][nx] == 6)
break;
y = ny;
x = nx;
visited[ny][nx] = 1;
}
dir = (dir + i) % 4;
y = curY;
x = curX;
}
}
void visitedClear()
{
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
visited[i][j] = 0;
}
}
}
int checkResult()
{
int res = 0;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
if (board[i][j] == 1 || board[i][j] == 2 || board[i][j] == 3 || board[i][j] == 4 || board[i][j] == 5 || board[i][j] == 6)
continue;
if (visited[i][j] == 0 )
res++;
}
}
return res;
}
void printVisited()
{
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
cout << visited[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
void DFS(int s, int L)
{
if (L == cctvCount)
{
for (int i = 0; i < L; ++i)
{
// ch[i] ๊ฐ dir
// i๋ cctv์ธ๋ฑ์ค
if (board[cctvs[i].first][cctvs[i].second] == 1)
{
CCTV1(cctvs[i].first, cctvs[i].second, ch[i]);
}
else if (board[cctvs[i].first][cctvs[i].second] == 2)
{
CCTV2(cctvs[i].first, cctvs[i].second, ch[i]);
}
else if (board[cctvs[i].first][cctvs[i].second] == 3)
{
CCTV3(cctvs[i].first, cctvs[i].second, ch[i]);
}
else if (board[cctvs[i].first][cctvs[i].second] == 4)
{
CCTV4(cctvs[i].first, cctvs[i].second, ch[i]);
}
else if (board[cctvs[i].first][cctvs[i].second] == 5)
{
CCTV5(cctvs[i].first, cctvs[i].second, ch[i]);
}
}
res = min(res, checkResult());
//printVisited();
visitedClear();
//cout << ch[i] << " ";
//cout << endl;
}
else
{
for (int i = 0; i < 4; ++i)
{
ch[L] = i;
DFS(i + 1, L + 1);
}
}
}
void solve()
{
cin >> n >> m;
board = vector<vector<int>>(n + 1, vector<int>(m + 1));
visited = vector<vector<int>>(n + 1, vector<int>(m + 1));
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
cin >> board[i][j];
if (board[i][j] >= 1 && board[i][j] <= 5)
cctvs.push_back({ i, j });
}
}
cctvCount = cctvs.size();
DFS(0, 0);
cout << res;
// cctv๊ฐ 3๊ฐ
// ๊ฒฝ์ฐ์ ์
// 0 0 0
// 0 0 1
// 0 0 2
// 0 0 3
// 0 1 0
// 0 1 1
// 0 1 2
// 0 1 3
// 0 2 0
// ...
// 4 * 4 * 4
// 64
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
freopen("input.txt", "rt", stdin);
solve();
return 0;
}