Skip to content

Commit 05495ca

Browse files
committed
82차 1번 문제풀이
1 parent bed337f commit 05495ca

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

live8/test82/문제1/황장현.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const fs = require('fs');
2+
3+
const input = fs
4+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
5+
.toString()
6+
.trim()
7+
.split('\n')
8+
.map((el) => el.split(' ').map(Number));
9+
10+
function solution(input) {
11+
const [n, m] = input[0];
12+
const drawing = input.slice(1).map((row) => [...row]);
13+
14+
const dx = [-1, 1, 0, 0];
15+
const dy = [0, 0, -1, 1];
16+
17+
let count = 0;
18+
let maxSize = 0;
19+
20+
function dfs(x, y) {
21+
let size = 1;
22+
drawing[x][y] = 0;
23+
24+
for (let i = 0; i < 4; i++) {
25+
const nx = x + dx[i];
26+
const ny = y + dy[i];
27+
28+
if (nx >= 0 && nx < n && ny >= 0 && ny < m && drawing[nx][ny] === 1) {
29+
size += dfs(nx, ny);
30+
}
31+
}
32+
return size;
33+
}
34+
35+
for (let i = 0; i < n; i++) {
36+
for (let j = 0; j < m; j++) {
37+
if (drawing[i][j] === 1) {
38+
count++;
39+
maxSize = Math.max(maxSize, dfs(i, j));
40+
}
41+
}
42+
}
43+
44+
console.log(count);
45+
console.log(maxSize);
46+
}
47+
48+
solution(input);

0 commit comments

Comments
 (0)