Skip to content

Commit c178cd6

Browse files
committed
98차 1번 문제풀이
1 parent e2fc721 commit c178cd6

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const fs = require("fs");
2+
const input = fs
3+
.readFileSync("./input.txt", "utf8")
4+
// .readFileSync("/dev/stdin", "utf8")
5+
.toString()
6+
.trim()
7+
.split("\n")
8+
.map((line) => line.split(" "));
9+
10+
function solution(input) {
11+
const [N, M] = input[0];
12+
const snow = input[1].map(Number);
13+
14+
let maxSize = 0;
15+
let count = 0; // 디버깅용
16+
17+
function dfs(position, time, size) {
18+
count++;
19+
// console.log("count:", count, [position, time, size, maxSize]); // 디버깅용
20+
if (time > M) return;
21+
// 시간 초과 시 종료
22+
if (size > maxSize) maxSize = size; // 최대값 갱신
23+
24+
if (position + 1 < N) {
25+
dfs(position + 1, time + 1, size + snow[position + 1]);
26+
}
27+
if (position + 2 < N) {
28+
dfs(position + 2, time + 1, Math.trunc(size / 2) + snow[position + 2]);
29+
}
30+
}
31+
32+
dfs(-1, 0, 1);
33+
34+
return maxSize;
35+
}
36+
37+
console.log(solution(input));

0 commit comments

Comments
 (0)