Skip to content

Commit

Permalink
이슈 #392에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 26, 2024
1 parent 5e7275f commit eff0018
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Programmers/안전지대.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <string>
#include <vector>

using namespace std;

const vector<pair<int, int>> directions = {
{-1, -1}, {-1, 0}, {-1, 1},
{0, -1}, {0, 1},
{1, -1}, {1, 0}, {1, 1}
};

int solution(vector<vector<int>> board) {
int n = board.size();
vector<vector<bool>> dangerZone(n, vector<bool>(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;
}

0 comments on commit eff0018

Please sign in to comment.