Skip to content

Commit 85222d6

Browse files
Merge pull request #655 from eric-hjh/main
[황장현] 98차 라이브 코테 제출
2 parents dc8a118 + 8398256 commit 85222d6

3 files changed

Lines changed: 94 additions & 0 deletions

File tree

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 [N, M] = input[0];
10+
const numArr = [0, ...input[1]];
11+
12+
function bF(idx, sec, size) {
13+
if (sec > M) return 0;
14+
if (sec === M || idx >= N) return size;
15+
16+
let ans = 0;
17+
ans = Math.max(
18+
idx + 1 <= N ? bF(idx + 1, sec + 1, size + numArr[idx + 1]) : 0,
19+
idx + 2 <= N
20+
? bF(idx + 2, sec + 1, Math.floor(size / 2) + numArr[idx + 2])
21+
: 0
22+
);
23+
24+
return ans;
25+
}
26+
27+
return bF(0, 0, 1);
28+
}
29+
30+
console.log(solution(input));

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim();
5+
6+
function solution(input) {
7+
const digits = input.split('');
8+
const visited = Array(digits.length).fill(false);
9+
let found = Infinity;
10+
11+
function dfs(current) {
12+
if (current.length === digits.length) {
13+
const num = parseInt(current.join(''), 10);
14+
if (num > parseInt(input, 10)) {
15+
found = Math.min(found, num);
16+
}
17+
return;
18+
}
19+
20+
for (let i = 0; i < digits.length; i++) {
21+
if (!visited[i]) {
22+
visited[i] = true;
23+
current.push(digits[i]);
24+
dfs(current);
25+
current.pop();
26+
visited[i] = false;
27+
}
28+
}
29+
}
30+
31+
dfs([]);
32+
33+
return found === Infinity ? 0 : found;
34+
}
35+
36+
console.log(solution(input));

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function solution(prices) {
2+
const stack = [],
3+
result = Array(prices.length)
4+
.fill(0)
5+
.map((_, idx) => idx)
6+
.reverse();
7+
const visited = [];
8+
9+
prices.forEach((price, idx) => {
10+
const sLastIdx = stack.length - 1;
11+
12+
if (price < stack[sLastIdx]) {
13+
let backTrackingIdx = 0;
14+
15+
while (price < stack[sLastIdx - backTrackingIdx]) {
16+
if (!visited[sLastIdx - backTrackingIdx]) {
17+
result[sLastIdx - backTrackingIdx] -= prices.length - 1 - idx;
18+
visited[sLastIdx - backTrackingIdx] = true;
19+
}
20+
backTrackingIdx++;
21+
}
22+
}
23+
stack.push(price);
24+
});
25+
return result;
26+
}
27+
28+
console.log(solution([1, 2, 3, 2, 3]));

0 commit comments

Comments
 (0)