Skip to content

Commit f1700ce

Browse files
authored
Merge pull request #597 from sangminlee98/main
[이상민] 85차 라이브 코테 제출
2 parents 10208ff + 7ae53a0 commit f1700ce

3 files changed

Lines changed: 123 additions & 0 deletions

File tree

live8/test85/문제1/이상민.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const input = require("fs")
2+
.readFileSync(process.platform === "linux" ? "/dev/stdin" : "./input.txt")
3+
.toString()
4+
.trim()
5+
.split("\n");
6+
7+
const answer = [];
8+
const arr = [];
9+
10+
for (let i = 2; i < input.length; i += 2) {
11+
arr.push(input[i].split(" ").map(Number));
12+
}
13+
14+
for (let i = 0; i < arr.length; i++) {
15+
const tmp = arr[i].sort((a, b) => a - b);
16+
const n = tmp.length;
17+
let count = 0;
18+
19+
for (let j = 1; j < n - 1; j++) {
20+
const mid = tmp[j];
21+
let left = j - 1;
22+
let right = j + 1;
23+
24+
while (left >= 0 && right < n) {
25+
const leftDiff = mid - tmp[left];
26+
const rightDiff = tmp[right] - mid;
27+
28+
if (leftDiff === rightDiff) {
29+
count++;
30+
left--;
31+
right++;
32+
} else if (leftDiff < rightDiff) {
33+
left--;
34+
} else {
35+
right++;
36+
}
37+
}
38+
}
39+
answer.push(count);
40+
}
41+
42+
console.log(answer.join("\n"));

live8/test85/문제2/이상민.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const input = require("fs")
2+
.readFileSync(process.platform === "linux" ? "/dev/stdin" : "./input.txt")
3+
.toString()
4+
.trim()
5+
.split("\n");
6+
7+
function bfs(x, y, visited, map) {
8+
const queue = [];
9+
const dx = [0, 1, 0, -1];
10+
const dy = [1, 0, -1, 0];
11+
12+
queue.push([x, y]);
13+
14+
while (queue.length) {
15+
const [currX, currY] = queue.shift();
16+
17+
for (let i = 0; i < 4; i++) {
18+
const newX = currX + dx[i];
19+
const newY = currY + dy[i];
20+
if (newX >= 0 && newX < map[0].length && newY >= 0 && newY < map.length) {
21+
if (map[newY][newX] === "#" && !visited[newY][newX]) {
22+
visited[newY][newX] = true;
23+
queue.push([newX, newY]);
24+
}
25+
}
26+
}
27+
}
28+
}
29+
30+
function solution(h, w, map) {
31+
const visited = Array.from({ length: h }, () => Array(w).fill(false));
32+
let count = 0;
33+
34+
for (let i = 0; i < h; i++) {
35+
for (let j = 0; j < w; j++) {
36+
if (map[i][j] === "#" && !visited[i][j]) {
37+
bfs(j, i, visited, map);
38+
count++;
39+
}
40+
}
41+
}
42+
43+
return count;
44+
}
45+
46+
const tmp = [];
47+
let T = 1;
48+
49+
while (true) {
50+
if (T >= input.length) break;
51+
const [w, h] = input[T].split(" ").map(Number);
52+
const map = [];
53+
for (let i = T + 1; i <= T + w; i++) {
54+
map.push(input[i]);
55+
}
56+
tmp.push([w, h, map]);
57+
T += w + 1;
58+
}
59+
60+
const answer = [];
61+
62+
for (const t of tmp) {
63+
answer.push(solution(...t));
64+
}
65+
66+
console.log(answer.join("\n"));

live8/test85/문제3/이상민.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function solution(clothes) {
2+
let answer = 1;
3+
const map = new Map();
4+
for (const cloth of clothes) {
5+
const [name, type] = cloth;
6+
if (!map.has(type)) map.set(type, 1);
7+
else map.set(type, map.get(type) + 1);
8+
}
9+
10+
for (const key of map.keys()) {
11+
answer *= map.get(key) + 1;
12+
}
13+
14+
return answer - 1;
15+
}

0 commit comments

Comments
 (0)