-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb1062.js
More file actions
49 lines (43 loc) · 1.03 KB
/
b1062.js
File metadata and controls
49 lines (43 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var fs = require("fs");
var input = fs.readFileSync("/dev/stdin").toString().trim().split("\n");
const [N, K] = input[0].split(" ").map(Number);
let words = input.slice(1);
const selected = new Set([97, 110, 116, 99, 105]);
let max = -Infinity;
if (5 > K) {
console.log(0);
} else {
words = words.map((word) => word.slice(4, word.length - 4));
function recursion(n) {
if (selected.size === K) {
let cnt = 0;
for (const word of words) {
let isReadable = true;
for (let i = 0; i < word.length; i++) {
if (!selected.has(word[i].charCodeAt())) {
isReadable = false;
break;
}
}
if (isReadable) {
cnt += 1;
}
}
max = max < cnt ? cnt : max;
return;
}
if (n > 25) {
return;
}
// 97
const charCode = 97 + n;
if (!selected.has(charCode)) {
selected.add(charCode);
recursion(n + 1);
selected.delete(charCode);
}
recursion(n + 1);
}
recursion(0);
console.log(max);
}