From eff0018b19ccc078cdccfcf295ae9207adf40699 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 26 Nov 2024 13:39:36 +0000 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EC=8A=88=20#392=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=86=94=EB=A3=A8=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\240\204\354\247\200\353\214\200.cpp" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "Programmers/\354\225\210\354\240\204\354\247\200\353\214\200.cpp" diff --git "a/Programmers/\354\225\210\354\240\204\354\247\200\353\214\200.cpp" "b/Programmers/\354\225\210\354\240\204\354\247\200\353\214\200.cpp" new file mode 100644 index 0000000..8bb5ee0 --- /dev/null +++ "b/Programmers/\354\225\210\354\240\204\354\247\200\353\214\200.cpp" @@ -0,0 +1,41 @@ +#include +#include + +using namespace std; + +const vector> directions = { + {-1, -1}, {-1, 0}, {-1, 1}, + {0, -1}, {0, 1}, + {1, -1}, {1, 0}, {1, 1} +}; + +int solution(vector> board) { + int n = board.size(); + vector> dangerZone(n, vector(n, false)); + + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (board[i][j] == 1) { + dangerZone[i][j] = true; + for (const auto& dir : directions) { + int ni = i + dir.first; + int nj = j + dir.second; + if (ni >= 0 && ni < n && nj >= 0 && nj < n) { + dangerZone[ni][nj] = true; + } + } + } + } + } + + int safeCount = 0; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (!dangerZone[i][j]) { + ++safeCount; + } + } + } + + return safeCount; +} \ No newline at end of file