Skip to content

Commit 557bfb9

Browse files
Merge pull request #675 from jinoo0306/main
[조진우] 102차 라이브 코테 제출
2 parents c43ee3b + ebe366e commit 557bfb9

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 = input;
13+
14+
const an = [];
15+
an[0] = 0;
16+
an[1] = 1;
17+
// an[2] = 3;
18+
// an[3] = 5;
19+
// an[4] = 11;
20+
// an[5] = 21;
21+
// an[6] = 43;
22+
for (let i = 2; i <= N; i++) {
23+
an[i] = (an[i - 1] * 2 + (i % 2 === 1 ? -1 : 1)) % 10007;
24+
// console.log(`A(${i}) = ${an[i]}`);
25+
}
26+
27+
return an[N];
28+
}
29+
30+
console.log(solution(input));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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((line) => line.split(" ").map(Number));
15+
16+
function solution(input) {
17+
const N = input[0];
18+
const stocks = [...input[1]];
19+
let max = 0;
20+
let dp = stocks[0]; // 주식의 최소값을 기억
21+
22+
for (let i = 1; i < N; i++) {
23+
if (stocks[i] - dp > 0) max = Math.max(max, stocks[i] - dp);
24+
if (stocks[i] < dp) dp = stocks[i];
25+
}
26+
27+
return max;
28+
}
29+
30+
console.log(solution(input));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function solution(x, y, n) {
2+
const visited = new Set([x]);
3+
const queue = [[x, 0]];
4+
let queueIndex = 0;
5+
6+
while (queueIndex < queue.length) {
7+
const [current, count] = queue[queueIndex++];
8+
if (current === y) return count;
9+
10+
const calculate = [current + n, current * 2, current * 3];
11+
12+
for (const cal of calculate) {
13+
if (cal <= y && !visited.has(cal)) {
14+
visited.add(cal);
15+
queue.push([cal, count + 1]);
16+
}
17+
}
18+
}
19+
20+
return -1;
21+
}
22+
23+
console.log(solution(10, 40, 30));

0 commit comments

Comments
 (0)