Skip to content

Commit 53d1b42

Browse files
Merge pull request #591 from eric-hjh/main
[황장현] 82차 라이브 코테 제출
2 parents bed337f + 8cfb1fb commit 53d1b42

2 files changed

Lines changed: 81 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);

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 relation = input.slice(1);
13+
const graph = Array.from({ length: N + 1 }).map((_) =>
14+
Array.from({ length: 0 })
15+
);
16+
17+
for (const [f1, f2] of relation) {
18+
graph[f1].push(f2);
19+
graph[f2].push(f1);
20+
}
21+
22+
function dfs(start, target) {}
23+
24+
for (let i = 1; i <= N; i++) {
25+
const temp = [];
26+
for (let j = 1; j <= N; j++) {
27+
if (graph[i].includes(j)) temp.push(1);
28+
else dfs(i, j);
29+
}
30+
}
31+
}
32+
33+
console.log(solution(input));

0 commit comments

Comments
 (0)