Skip to content

Commit

Permalink
#19 23.02.03 > 4 > 연구소
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Feb 3, 2023
1 parent 2815156 commit 5144d86
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/bj/gold/4/14502.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"use strict";

const [[n, m], ...inputs] = require("fs")
.readFileSync("/dev/stdin")
.toString()
.trim()
.split("\n")
.map((v) => v.split(" ").map(Number));

const solution = (col, row, board) => {
const dx = [0, 0, 1, -1];
const dy = [1, -1, 0, 0];
let ans = 0;

const countingSafeZone = (arr) => {
let cnt = 0;
let queue = [];

for (let i = 0; i < col; i++) {
for (let j = 0; j < row; j++) {
if (arr[i][j] === 2) queue.push([i, j]);
}
}

while (queue.length) {
const [curX, curY] = queue.shift();

for (let i = 0; i < 4; i++) {
const [nx, ny] = [curX + dx[i], curY + dy[i]];

if (nx >= 0 && nx < col && ny >= 0 && ny < row && arr[nx][ny] === 0) {
arr[nx][ny] = 2;
queue.push([nx, ny]);
}
}
}

for (let i = 0; i < col; i++) {
for (let j = 0; j < row; j++) {
if (arr[i][j] === 0) {
cnt += 1;
}
}
}

return cnt;
};

const dfs = (cnt) => {
if (cnt === 3) {
let arr = board.map((v) => [...v]);
let cntOfSafe = countingSafeZone(arr);

ans = Math.max(ans, cntOfSafe);
return;
}

for (let i = 0; i < col; i++) {
for (let j = 0; j < row; j++) {
if (board[i][j] === 0) {
board[i][j] = 1;
dfs(cnt + 1);
board[i][j] = 0;
}
}
}
};

dfs(0);
return ans;
};

console.log(solution(n, m, inputs));
5 changes: 5 additions & 0 deletions src/bj/gold/4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Gold 4

| | 문제번호 | 문제명 | 응시 날짜 | 채점 결과 | 재응시 |
| :-: | :------: | :------------------: | :-------: | :-------: | :----: |
| 1 | 14502 | [연구소](./14502.js) | 23.02.03 | X |

0 comments on commit 5144d86

Please sign in to comment.