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