Skip to content

Commit e9bdc70

Browse files
Merge pull request #671 from jinoo0306/main
[조진우] 101차 라이브 코테 제출
2 parents 18fdea9 + c5a9224 commit e9bdc70

3 files changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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
10+
.readFileSync(filePath, "utf8")
11+
.toString()
12+
.trim()
13+
.split("\n")
14+
.map(Number);
15+
16+
function solution(input) {
17+
const T = input[0];
18+
const arr = input.slice(1);
19+
const result = [];
20+
21+
function dfs(sum, target) {
22+
if (sum === target) return 1;
23+
if (sum > target) return 0;
24+
25+
return dfs(sum + 1, target) + dfs(sum + 2, target) + dfs(sum + 3, target);
26+
}
27+
28+
for (let i = 0; i < T; i++) {
29+
const n = arr[i];
30+
result.push(dfs(0, n));
31+
}
32+
33+
return result;
34+
}
35+
36+
console.log(solution(input).join("\n"));
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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
10+
.readFileSync(filePath, "utf8")
11+
.toString()
12+
.trim()
13+
.split("\n")
14+
.map((value) => value.split(" ").map(Number));
15+
16+
function solution(input) {
17+
const N = input[0][0];
18+
const costs = input.slice(1);
19+
const dp = [...costs[0]];
20+
21+
for (let i = 1; i < N; i++) {
22+
const temp = [0, 0, 0];
23+
for (let j = 0; j < 3; j++) {
24+
if (j === 0) temp[0] = costs[i][0] + Math.min(dp[1], dp[2]);
25+
else if (j === 1) temp[1] = costs[i][1] + Math.min(dp[0], dp[2]);
26+
else if (j === 2) temp[2] = costs[i][2] + Math.min(dp[0], dp[1]);
27+
}
28+
dp.splice(0, 3, ...temp);
29+
}
30+
31+
return Math.min(...dp);
32+
}
33+
34+
console.log(solution(input));
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
function solution(n, edge) {
2+
const map = Array(n + 1)
3+
.fill()
4+
.map(() => []);
5+
for (let i = 0; i < edge.length; i++) {
6+
let a = edge[i][0];
7+
let b = edge[i][1];
8+
map[a].push(b);
9+
map[b].push(a);
10+
}
11+
12+
const visited = Array(n + 1).fill(0);
13+
const q = [];
14+
q.push(1);
15+
visited[1] = 1;
16+
17+
while (q.length > 0) {
18+
const now = q.shift();
19+
for (let i = 0; i < map[now].length; i++) {
20+
let next = map[now][i];
21+
if (visited[next] === 0) {
22+
visited[next] = visited[now] + 1;
23+
q.push(next);
24+
}
25+
}
26+
}
27+
28+
let max = 0;
29+
for (let i = 0; i < visited.length; i++) {
30+
if (visited[i] > max) {
31+
max = visited[i];
32+
}
33+
}
34+
35+
let answer = 0;
36+
for (let i = 0; i < visited.length; i++) {
37+
if (visited[i] === max) {
38+
answer++;
39+
}
40+
}
41+
42+
return answer;
43+
}
44+
45+
console.log(
46+
solution([
47+
[3, 6],
48+
[4, 3],
49+
[3, 2],
50+
[1, 3],
51+
[1, 2],
52+
[2, 4],
53+
[5, 2],
54+
])
55+
);

0 commit comments

Comments
 (0)