Skip to content

Commit 38caa2f

Browse files
Merge pull request #548 from eric-hjh/main
[황장현] 69차 라이브 코테 제출
2 parents 7a7cc21 + e856586 commit 38caa2f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

live6/test69/문제1/황장현.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' '));
7+
8+
function solution(input) {
9+
const [N, M] = input[0].map(Number);
10+
const prevChessBoard = input.slice(1).map((el) => el[0].split(''));
11+
12+
function checkChessBoard(chessBoard) {
13+
let whiteFirst = 0;
14+
let blackFirst = 0;
15+
for (let i = 0; i < 8; i++) {
16+
for (let j = 0; j < 8; j++) {
17+
const currentChessBlock = chessBoard[i][j];
18+
if ((i + j) % 2 === 0) {
19+
if (currentChessBlock === 'W') {
20+
blackFirst++;
21+
} else {
22+
whiteFirst++;
23+
}
24+
} else {
25+
if (currentChessBlock === 'B') {
26+
blackFirst++;
27+
} else {
28+
whiteFirst++;
29+
}
30+
}
31+
}
32+
}
33+
return Math.min(whiteFirst, blackFirst);
34+
}
35+
36+
let minRepaint = Infinity;
37+
38+
for (let i = 0; i <= N - 8; i++) {
39+
for (let j = 0; j <= M - 8; j++) {
40+
const standardChessBoard = prevChessBoard
41+
.slice(i, i + 8)
42+
.map((row) => row.slice(j, j + 8));
43+
const repaint = checkChessBoard(standardChessBoard);
44+
minRepaint = Math.min(minRepaint, repaint);
45+
}
46+
}
47+
48+
return minRepaint;
49+
}
50+
51+
console.log(solution(input));

0 commit comments

Comments
 (0)