Skip to content

Commit cb10e08

Browse files
Merge pull request #630 from eric-hjh/main
[황장현] 92차 라이브 코테 제출
2 parents f5bde2c + 641c80e commit cb10e08

3 files changed

Lines changed: 179 additions & 0 deletions

File tree

live9/test92/문제1/황장현.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
class MinHeap {
2+
constructor() {
3+
this.heap = [];
4+
}
5+
push(value) {
6+
this.heap.push(value);
7+
this.bubbleUp();
8+
}
9+
10+
pop() {
11+
if (this.heap.length === 1) return this.heap.pop();
12+
const min = this.heap[0];
13+
this.heap[0] = this.heap.pop();
14+
this.bubbleDown();
15+
return min;
16+
}
17+
18+
bubbleUp() {
19+
let index = this.heap.length - 1;
20+
21+
while (index > 0) {
22+
const parentIndex = Math.floor((index - 1) / 2);
23+
if (this.heap[parentIndex] <= this.heap[index]) break;
24+
[this.heap[parentIndex], this.heap[index]] = [
25+
this.heap[index],
26+
this.heap[parentIndex],
27+
];
28+
index = parentIndex;
29+
}
30+
}
31+
32+
// 루트 값을 뺐을 때 재정렬
33+
bubbleDown() {
34+
let index = 0;
35+
const length = this.heap.length;
36+
37+
while (true) {
38+
const left = 2 * index + 1;
39+
const right = 2 * index + 2;
40+
let smallest = index;
41+
42+
if (left < length && this.heap[left] < this.heap[smallest]) {
43+
smallest = left;
44+
}
45+
46+
if (right < length && this.heap[right] < this.heap[smallest]) {
47+
smallest = right;
48+
}
49+
50+
if (smallest === index) break;
51+
52+
[this.heap[index], this.heap[smallest]] = [
53+
this.heap[smallest],
54+
this.heap[index],
55+
];
56+
57+
index = smallest;
58+
}
59+
}
60+
61+
least() {
62+
return this.heap[0];
63+
}
64+
65+
size() {
66+
return this.heap.length;
67+
}
68+
}
69+
70+
function solution(scoville, K) {
71+
scoville.sort((a, b) => a - b);
72+
if (scoville[0] >= K) return 0;
73+
74+
const minHeap = new MinHeap();
75+
scoville.forEach((s) => minHeap.push(s));
76+
let mixCount = 0;
77+
while (minHeap.size() > 1 && minHeap.least() < K) {
78+
const first = minHeap.pop();
79+
const second = minHeap.pop();
80+
const newScoville = first + second * 2;
81+
minHeap.push(newScoville);
82+
mixCount++;
83+
}
84+
85+
return minHeap.least() >= K ? mixCount : -1;
86+
}
87+
88+
console.log(solution([1, 2, 3, 9, 10, 12], 7));

live9/test92/문제2/황장현.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function solution(board, skill) {
2+
let count = 0;
3+
let effectMap = Array.from({ length: board.length + 1 }, () =>
4+
Array(board[0].length + 1).fill(0)
5+
);
6+
7+
for (let i = 0; i < skill.length; ++i) {
8+
const [skillType, r1, c1, r2, endCol, degree] = skill[i];
9+
const adjustedImpact = skillType === 1 ? -degree : degree;
10+
11+
effectMap[r1][c1] += adjustedImpact;
12+
effectMap[r1][endCol + 1] -= adjustedImpact;
13+
effectMap[r2 + 1][c1] -= adjustedImpact;
14+
effectMap[r2 + 1][endCol + 1] += adjustedImpact;
15+
}
16+
17+
for (let i = 0; i < board.length; ++i) {
18+
for (let j = 0; j < board[i].length; ++j) {
19+
if (i > 0) effectMap[i][j] += effectMap[i - 1][j];
20+
if (j > 0) effectMap[i][j] += effectMap[i][j - 1];
21+
if (i > 0 && j > 0) effectMap[i][j] -= effectMap[i - 1][j - 1];
22+
}
23+
}
24+
25+
for (let i = 0; i < board.length; ++i) {
26+
for (let j = 0; j < board[i].length; ++j) {
27+
board[i][j] += effectMap[i][j];
28+
if (board[i][j] > 0) {
29+
count++;
30+
}
31+
}
32+
}
33+
34+
return count;
35+
}
36+
37+
console.log(
38+
solution(
39+
[
40+
[5, 5, 5, 5, 5],
41+
[5, 5, 5, 5, 5],
42+
[5, 5, 5, 5, 5],
43+
[5, 5, 5, 5, 5],
44+
],
45+
[
46+
[1, 0, 0, 3, 4, 4],
47+
[1, 2, 0, 2, 3, 2],
48+
[2, 1, 0, 3, 1, 2],
49+
[1, 0, 1, 3, 3, 1],
50+
]
51+
)
52+
);

live9/test92/문제3/황장현.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function solution(book_time) {
2+
const toMinutes = (time) => {
3+
const [hour, minute] = time.split(':').map(Number);
4+
return hour * 60 + minute;
5+
};
6+
7+
book_time.sort((a, b) => toMinutes(a[0]) - toMinutes(b[0]));
8+
9+
const rooms = [];
10+
11+
for (const [start, end] of book_time) {
12+
const startTime = toMinutes(start);
13+
const endTime = toMinutes(end) + 10;
14+
15+
let earliestRoomIndex = rooms.findIndex(
16+
(roomEndTime) => roomEndTime <= startTime
17+
);
18+
19+
if (earliestRoomIndex !== -1) {
20+
rooms[earliestRoomIndex] = endTime;
21+
} else {
22+
rooms.push(endTime);
23+
}
24+
25+
rooms.sort((a, b) => a - b);
26+
}
27+
28+
return rooms.length;
29+
}
30+
31+
console.log(
32+
solution([
33+
['15:00', '17:00'],
34+
['16:40', '18:20'],
35+
['14:20', '15:20'],
36+
['14:10', '19:20'],
37+
['18:20', '21:20'],
38+
])
39+
);

0 commit comments

Comments
 (0)