Skip to content

Commit 1eb3320

Browse files
Merge pull request #664 from jinoo0306/main
[조진우] 100차 라이브 코테 제출
2 parents b0c1cc0 + 6e4f204 commit 1eb3320

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

live9/test100/문제1/조진우.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const filePath =
5+
process.platform === "linux"
6+
? "/dev/stdin"
7+
: path.join(__dirname, "input.txt");
8+
9+
const input = fs.readFileSync(filePath, "utf8").toString().trim();
10+
11+
function solution(input) {
12+
const N = Number(input);
13+
const romaNum = [1, 5, 10, 50];
14+
const result = [];
15+
16+
function dfs(index, sum, start) {
17+
if (index === N) {
18+
result.push(sum);
19+
return;
20+
}
21+
22+
for (let i = start; i < romaNum.length; i++)
23+
dfs(index + 1, sum + romaNum[i], i);
24+
}
25+
26+
dfs(0, 0, 0);
27+
28+
return [...new Set(result)].length;
29+
}
30+
31+
console.log(solution(input));

live9/test100/문제2/조진우.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const filePath =
5+
process.platform === "linux"
6+
? "/dev/stdin"
7+
: path.join(__dirname, "input.txt");
8+
9+
const input = fs.readFileSync(filePath, "utf8").toString().trim();
10+
11+
function solution(input) {
12+
const N = Number(input);
13+
let answer = 0;
14+
15+
function check(array, row, col) {
16+
for (let i = 0; i < row; i++) {
17+
if (array[i] === col) return false;
18+
if (Math.abs(i - row) === Math.abs(array[i] - col)) return false;
19+
}
20+
return true;
21+
}
22+
23+
function dfs(row, array) {
24+
if (row === N) {
25+
answer++;
26+
return;
27+
}
28+
29+
for (let i = 0; i < N; i++) {
30+
if (check(array, row, i)) {
31+
array[row] = i;
32+
dfs(row + 1, array);
33+
array[row] = 0;
34+
}
35+
}
36+
}
37+
38+
const arr = new Array(N).fill(0);
39+
dfs(0, arr);
40+
return answer;
41+
}
42+
43+
console.log(solution(input));

live9/test100/문제3/조진우.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function solution(queue1, queue2) {
2+
const totalLength = queue1.length + queue2.length;
3+
const merged = [...queue1, ...queue2];
4+
5+
let sum1 = queue1.reduce((a, b) => a + b, 0);
6+
let sum2 = queue2.reduce((a, b) => a + b, 0);
7+
const target = (sum1 + sum2) / 2;
8+
9+
if ((sum1 + sum2) % 2 !== 0) return -1;
10+
11+
let p1 = 0;
12+
let p2 = queue1.length;
13+
let moveCount = 0;
14+
15+
while (moveCount <= totalLength * 3) {
16+
if (sum1 === target) return moveCount;
17+
18+
if (sum1 > target) {
19+
sum1 -= merged[p1];
20+
p1++;
21+
} else {
22+
sum1 += merged[p2];
23+
p2++;
24+
}
25+
26+
moveCount++;
27+
}
28+
29+
return -1;
30+
}

0 commit comments

Comments
 (0)