Skip to content

Commit aa4629f

Browse files
[BOJ] 15961 회전 초밥 (G4)
1 parent f7ff2c1 commit aa4629f

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

서정우/4주차/260120.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// 월급날 하루전!
2+
const fs = require("fs");
3+
const filePath = process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
4+
const input = fs.readFileSync(filePath).toString().trim().split("\n");
5+
6+
const [N, d, k, c] = input[0].split(" ").map(Number);
7+
const sushies = input.slice(1).map(Number);
8+
9+
let maxKind = 0;
10+
const window = new Map();
11+
12+
for (let i = 0; i < k; i++) {
13+
window.set(sushies[i], (window.get(sushies[i]) || 0) + 1);
14+
}
15+
16+
for (let i = 0; i < N; i++) {
17+
let kind = window.size;
18+
if (!window.has(c)) {
19+
kind++;
20+
}
21+
maxKind = Math.max(maxKind, kind);
22+
23+
const removeIdx = i;
24+
const addIdx = (i + k) % N;
25+
26+
if (window.get(sushies[removeIdx]) === 1) {
27+
window.delete(sushies[removeIdx]);
28+
} else {
29+
window.set(sushies[removeIdx], window.get(sushies[removeIdx]) - 1);
30+
}
31+
32+
window.set(sushies[addIdx], (window.get(sushies[addIdx]) || 0) + 1);
33+
}
34+
35+
console.log(maxKind);

서정우/input.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
4
1+
8 30 4 30
2+
7
3+
9
4+
7
5+
30
6+
2
7+
7
8+
9
9+
25

0 commit comments

Comments
 (0)