Skip to content

Commit 0dc2a27

Browse files
Merge pull request #594 from eric-hjh/main
[황장현] 84차 라이브 코테 제출
2 parents 61949bd + 167fb2f commit 0dc2a27

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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(' ').map(Number));
7+
8+
function solution(input) {
9+
const T = input[0];
10+
let idx = 1;
11+
let result = [];
12+
for (let i = 0; i < T; i++) {
13+
const [N, M] = input[idx];
14+
const A = input[idx + 1];
15+
const B = input[idx + 2];
16+
A.sort((a, b) => a - b);
17+
B.sort((a, b) => a - b);
18+
let count = 0;
19+
const bMaxNum = Math.max(...B);
20+
21+
for (let j = 0; j < N; j++) {
22+
if (A[j] > bMaxNum) {
23+
count += M;
24+
continue;
25+
}
26+
for (let k = 0; k < M; k++) {
27+
if (A[j] > B[k]) count++;
28+
else break;
29+
}
30+
}
31+
result.push(count);
32+
33+
idx += 3;
34+
}
35+
return result.join('\n');
36+
}
37+
38+
console.log(solution(input));
39+
40+
// 노가다로 풀었더니 이진탐색이랑 4배 차이 ㄷㄷ
41+
// 배열에서 원하값 찾을 때 이진탐색 생각하기

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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(' ').map(Number));
7+
8+
function solution(input) {
9+
const [K, N] = input[0];
10+
const lanList = input.slice(1);
11+
12+
let low = 1;
13+
let high = Math.max(...lanList);
14+
let answer = 0;
15+
16+
while (low <= high) {
17+
let mid = Math.floor((low + high) / 2);
18+
let count = lanList.reduce((acc, cur) => acc + Math.floor(cur / mid), 0);
19+
20+
if (count >= N) {
21+
answer = mid;
22+
low = mid + 1;
23+
} else {
24+
high = mid - 1;
25+
}
26+
}
27+
28+
return answer;
29+
}
30+
31+
console.log(solution(input));

live8/test84/문제3/황장현.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function solution(skill, skill_trees) {
2+
let count = 0;
3+
4+
skill_trees.forEach((tree) => {
5+
let filtered = tree
6+
.split('')
7+
.filter((s) => skill.includes(s))
8+
.join('');
9+
if (skill.startsWith(filtered)) count++;
10+
});
11+
12+
return count;
13+
}
14+
15+
console.log(solution('CBD', ['BACDE', 'CBADF', 'AECB', 'BDA']));

0 commit comments

Comments
 (0)