-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Gold 4 | ||
|
||
| | 문제번호 | 문제명 | 응시 날짜 | 채점 결과 | 재응시 | | ||
| :-: | :------: | :------------------: | :-------: | :-------: | :----: | | ||
| 1 | 14502 | [연구소](./14502.js) | 23.02.03 | X | |